Working directory behavior in Rmd files

I understand the default behavior that code within R markdown files is executed within the document folder.

However, what I've noticed is that when Chunk Output InLine is selected this is the case, but when it's switched to Chunk Output in Console the behavior defaults back to executing in the current working directory.

Is this behavior expected?

My understanding is yes, this is expected. The working directory for code chunks in an Rmd document is (as you mentioned) the directory containing the file, but you can also set this specifically in the global Options panel under the R Markdown tab -- "Project" being where the .Rproj file is located, "Document" the Rmd document, and "Current" would be the console working directory.

I really like using here for this reason, as I am regularly messing this up in large projects with multiple notebooks. :laughing:

Thanks for the response. I understand that "Document" is the default and appreciate the callout to the here package. The unexpected behavior I was referring to was that with default settings unchanged (ie wd = "Document"), if you set chunk output to console then the working directory reverts back to the original wd.

It's not clear to me that this should be related to the working directory status.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.