-2

I would like to get the file path of the R script that I am running. eg

when I run the function it will return

"C:/Users/Forename.Surname/Documents/foo.R"

(I am running Rstudio)

David
  • 301
  • 1
  • 3
  • 8

1 Answers1

2

Use the getSrcDirectory() function. For example, if you put this in a file:

scriptPath <- function() {
    getSrcDirectory(scriptPath);
}

Then calling scriptPath() from will tell you where the script file is located.

Caleb
  • 124,013
  • 19
  • 183
  • 272