How to get R to recognize your working directory as its working directory? How to get R to recognize your working directory as its working directory? r r

How to get R to recognize your working directory as its working directory?


You should copy shortcut to R (R.lnk file) to desire folder. Then in "Properties" (right mouse button -> last option) delete anything in field "Start in..." in second tab ("Shortcut"?). If you start R with this shortcut working directory will be that one where the shortcut is.

I don't have english version of Windows so I'm not sure about field names, but they should be easy to find.

Similar questions were in R-windows-faq:

2.5 How do I run it?

2.10 How can I keep workspaces for different projects in different directories?

2.14 What are HOME and working directories?

In 2.14 is mentioned that

The working directory is the directory from which Rgui or Rterm was launched, unless a shortcut was used when it is given by the `Start in' field of the shortcut's properties.


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.


Save your workspace to the desired directory and thereafter you just open the workspace from Windows explorer.