According to the description, this should be what you need: https://cran.r-project.org/web/packages/scriptName/ I only got NULL, but I also only tried within Rstudio... Here are some related questions, although you've probably already tried the answers: https://stackoverflow.com/questions/18000708/find-location-of-current-r-file https://stackoverflow.com/questions/1815606/determine-path-of-the-executing-script
Berry ------------------------------------- ________________________________ From: R-package-devel <r-package-devel-boun...@r-project.org> on behalf of Tony Wilkes <tony_a_wil...@outlook.com> Sent: Thursday, November 23, 2023 20:39 To: r-package-devel@r-project.org <r-package-devel@r-project.org> Subject: [R-pkg-devel] Question regarding finding the source file location without R-packages outside of R-Studio 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]] ______________________________________________ R-package-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-package-devel [[alternative HTML version deleted]] ______________________________________________ R-package-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-package-devel