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.
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.