[R-pkg-devel] Question regarding finding the source file location without R-packages outside of R-Studio

Tony Wilkes tony_@_w||ke@ @end|ng |rom out|ook@com
Thu Nov 23 20:39:48 CET 2023


Hi everyone,

I have a question. I hope it's not a stupid question.

Suppose you'd want to perform version control and project isolation. You'd create a project folder (let's call it "MyProject"), and place all the R packages you need for that project inside a subfolder (let's say "MyProject/MyLibrary"). Now you create and run an R-script in "MyProject".
install.packages(), library(), etc. all have a lib.loc argument to specify the library path. So one can manually specify the path of your project, and then you'd have your project isolation and version control fully set-up.

But if I want to set-up the library path automatically, to make it portable, I would need to determine the script location. In RStudio I can use the 'rstudioapi' package, which is very stable, and so does not really require version control. But for outside R-Studio, I have not found a very stable package that also works.
I prefer not using external R packages that requires version control (i.e. a package that changes often-ish): you'd need the package to access the project library, but the project library to access the package.

This brings me to my actual question: is it possible to determine the source file location of an R script outside of R-Studio, without resorting to R packages ? Or else use an R package that is VERY stable (i.e. doesn't change every (half) a year, like tidyverse packages tend to do)? commandArgs() used to contain the script path (apparently), but it doesn't work for me.

By the way: I wish to get the script path in an interactive session.

Thank you in advance.

Kind regards,

Tony


	[[alternative HTML version deleted]]



More information about the R-package-devel mailing list