You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This way, we can also demonstrate how to deal with relative vs. absolute paths and recommend a project-based workflow.
Of course, this is complicated by the fact that notebooks generally assume the working directory to be in their storage location, rather than the root folder of the project.
Solutions
There are three levels on which this can be solved: For an individual code line, for all code chunks of a rmarkdown/Quarto document, or for all rmarkdown/Quarto documents in a project:
The package rprojroot is prefered for non-interactive use over here (source).
As rprojroot, here returns absolute paths which are user- and OS-specific, which does not play nice if caches or objects that contain these paths are shared with others.
RStudio settings
In RStudio, one can also set Tools > Global Options > R Markdown > Evaluate chunks in directory: Project
Of course, all code then relies on this setting, making it rather non-portable.
Providing opts_knit in Quarto header
In Quarto, one can also set the following in the header:
This way, we can also demonstrate how to deal with relative vs. absolute paths and recommend a project-based workflow.
Of course, this is complicated by the fact that notebooks generally assume the working directory to be in their storage location, rather than the root folder of the project.
Solutions
There are three levels on which this can be solved: For an individual code line, for all code chunks of a rmarkdown/Quarto document, or for all rmarkdown/Quarto documents in a project:
Individual code line
source
All code chunks
source
All documents
For rmarkdown, set
knit_root_dir
when rendering:For Quarto, set
execute-dir
within_quarto.yml
(source):Notes
rprojroot vs. here
The package
rprojroot
is prefered for non-interactive use overhere
(source).As
rprojroot
,here
returns absolute paths which are user- and OS-specific, which does not play nice if caches or objects that contain these paths are shared with others.RStudio settings
In RStudio, one can also set Tools > Global Options > R Markdown > Evaluate chunks in directory: Project
Of course, all code then relies on this setting, making it rather non-portable.
Providing
opts_knit
in Quarto headerIn Quarto, one can also set the following in the header:
This is, however, of little use, as it is not possible to calculate
root.dir
dynamically in this case.The text was updated successfully, but these errors were encountered: