0

I have set up a workflow governed by a Makefile.

Under code/ I have multiple *.r scripts each typically responsible for creating one output file (typically an RData file but could also be csv exports or png images, any file in principle)

code/.Rprofile contains some helper functions to bootstrap the whole project directory system and sources some helper functions etc.

The scripts in code/ need this functionality to work properly.

RStudio has the convenient menu entry to set working directory to source file location.

But could I also make it run .Rprofile in that directory if found? Or really just start R a fresh from the directory of the source file?

Sirius
  • 5,224
  • 2
  • 14
  • 21
  • Does this help? https://stackoverflow.com/questions/13672720/r-command-for-setting-working-directory-to-source-file-location-in-rstudio. R will only run an .Rprofile if it's found in the directory where you launch R. If you need helper functions, it would make more sense to put them in a file where you explicitly source() them or create your own package to encapsulate shared logic. If you are using a Makefile, you must just be running R or Rscript, right? Not RStudio? – MrFlick Jun 17 '21 at 17:14
  • Yeah, Rscript. I use .Rprofile to source my file with functions in it. The goal is to be able to run RStudio if you like, typically for development, or make and it should just work. An R package will be the solution for this in the end, just wondering how to best do it till then – Sirius Jun 17 '21 at 19:02

0 Answers0