How to use relative paths, relative to the project directory in an Rstudio notebook?

3.4k Views Asked by At

When working inside an R project, I like to use relative paths, relative to the root of the project directory. Since a couple of weeks, I have upgraded RStudio to the latest version which includes "R Notebooks".

Notebooks are great but the options which I used in my knitr documents doesn't work any more:

opts_knit$set(root.dir="../..")

I would like paths to be relative to the project directory and I don't want to use setwd() because this wouldn't give the same result in interactive mode and in knitting mode. Also I like to be able to source the entire knitr document multiple times and changing to a relative directory setwd("..") multiple times quickly leads to an undesired path.

As suggested by Jennifer Bryan, is it necessary to use a package simply to set relative paths to files inside a project?

0

There are 0 best solutions below