Jim Raynor Jim Raynor - 6 months ago 37
R Question

Automatically finding the path of current R project in R Studio

Say I have an R project opened at the following directory

. Now I have a nested directory structure underneath and I am writing a function that is supposed to perform logging from anywhere inside this project and I want this function to write into files that are located at the directory
. I plan to pass the file path as an argument to this function. Now I know that this file will always be located under the /log directory in the project's main directory - but how do I automatically find out which is my project directory, so that I don't always specify relative paths with
. I wouldn't want to hard-code my local path
, but be able to detect this wherever I clone my project.


It sounds like the rprojroot package will provide what you're looking for -- in particular, the find_rstudio_root_file() function should provide what you need.