0

Every time I restart R I issue the following command:

setwd("C:/Users/avtarsingh/Downloads")

How do make this my permanent working dir

Bhail
  • 385
  • 1
  • 2
  • 18

3 Answers3

5

Create a file called ".Rprofile" and add that command. R will look for this file every time it starts and change to that directory accordingly. More info in the R documentation here

Stedy
  • 7,359
  • 14
  • 57
  • 77
  • 3
    And http://stackoverflow.com/questions/31433559/what-is-a-fool-proof-way-of-permanently-setting-r-working-directory but it's a bit more involved – Rich Scriven Aug 21 '15 at 23:33
  • Thanks. For now; Tools>Global Options>General ; In future as things get complex will read rest the material. – Bhail Aug 21 '15 at 23:44
2

In order to change your working directory permanently, you can find the following file “Rprofile.site” that is located in your installation path “etc” folder and open it in your favorite text editor (i.e., VSCode). Then you can add your permeant working directory to the first line, like the following line of code: setwd(“C:\your permeant working directory”) and save it. Next time you open the R-CRAN, your working directory is set to what you have saved.

Sara
  • 21
  • 1
1

Any code which you wish to run every R session can be added to Rprofile.site.

On a Windows machine, this file is located for example in C:\Program Files\R\R-3.1.2\etc. On Windows you will need to run your favourite text editor as an administrator to make changes to this file, since it is in Program Files.

This is also a good place to set your local CRAN repository, etc.

CSJCampbell
  • 2,025
  • 15
  • 19
  • Didn't find the file Rprofile.site in C:\Program Files\R\R-3.1.2 – Bhail Aug 21 '15 at 23:59
  • 1
    There is normally a directory 'etc' within the R-version directory. Is it not present? Do you normally have access to files in Program Files? – CSJCampbell Aug 22 '15 at 00:04