Compile Report within R Project - Paths and Structure Question

I have a R script (regular .R file) which is within an R project so if I open the R project and run interactively, the working directory is automatically set to the directory of the project. However, if I try to use the "Compile Report" feature in RStudio, the working directory is set to the folder where the program is. Why is it not set where the project is?

My folder structure looks like this:

  • MainFolder.Rproj
  • Programs
    -- Program.R
  • Data
    -- SomeCSVs.csv

I can make this work by putting the program instead in the main folder. Any other suggestions?

The here package enables references to file objects to be relative to the directory in which Rproj resides. This permits statements such as

readr::read_csv(here::here("Data/the_file.csv"))

to execute properly whether the R script is in the top level directory or Programs. This should obviate the need to adjust build tool settings.

1 Like

This topic was automatically closed 7 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.