I use R under Windows on several machines.
I know you can set the working directory from within an R script, like this
setwd(\"C:/Documents and Setti
You could use an environmental variable. This can work with Sys.getenv()
and Sys.setenv()
. For instance:
> Sys.setenv(R_TEST="testit")
> Sys.getenv("R_TEST")
R_TEST
"testit"
If you sent the variable in your script, you should be able to access it from within, and then call setwd()
on that output.
Just a detail: instead of reversing the slashes as you say, just add another backslash. Two of these \\ works the same way as one of these /. That makes it at least a little easier.
For Ubuntu:
Insert the following command into your .Rprofile
file (usually in your home directory):
setwd(Sys.getenv("PWD"))
Now your default working directory will be whatever directory you launched R from. Keep in mind you can also set up default workspaces in different directories by saving your workspace image as .RData
wherever you plan to launch R (startup sources .Rprofile
before searching for .Rdata
in the cwd
).