10

Possible Duplicate:
Change path.expand location (Win 7)

I would like to change the directory that path.expand("~/") references on a windows system. Currently this goes to "C:/Users/home/Documents/" by default. How does one change this? Note that this is distinct from the working directory that is set with setwd()

Community
  • 1
  • 1
Alex
  • 19,533
  • 37
  • 126
  • 195
  • Are you asking how to change the user's `My Documents` directory from your code? Don't do that. – SLaks Oct 22 '12 at 17:54
  • The user is me. I would like my code to be portable from my local machine to the grid (I switch off back and forth) and I need ~ to point to my projects directory not the Documents directory – Alex Oct 22 '12 at 17:55
  • Your second possible dup is only related. It's linux specific. – Brandon Bertelsen Oct 22 '12 at 17:56
  • It's also covered by R-windows FAQ 2.14: http://cran.r-project.org/bin/windows/base/rw-FAQ.html#What-are-HOME-and-working-directories_003f – Josh O'Brien Oct 22 '12 at 17:58
  • 1
    IMHO you're better off writing some "location validation" code that sets a local variable. Something like `my_path <- get_desired_working_location(whereami)` . That keeps you from mucking up standard location-related functions in the first place. – Carl Witthoft Oct 22 '12 at 18:08
  • 2
    @CarlWitthoft Actually, when working on Windows I change the directory as well so that everything syncs with my development files on dropbox, and does not require changes in path to be able to run. For example, if you point to ~/dev/ on both computers you dont' have to worry about usernames or any other path elements. You can run line-by-line code on both computers without issue. – Brandon Bertelsen Oct 22 '12 at 18:17
  • @BrandonBertelsen: that's exactly the use case. thank you for the help. – Alex Oct 22 '12 at 18:24

1 Answers1

11

You can change this by adding an R_USER variable to your Rprofile.site file.

Sys.setenv(R_USER="/my/desired/path/to/tilde")

This does not work on linux systems. See a related question: How to reset path.expand on tilde

Community
  • 1
  • 1
Brandon Bertelsen
  • 43,807
  • 34
  • 160
  • 255
  • You can also add this to your `Rprofile.R` file instead of `Rprofile.site`, in case you want the change to affect only your OS profile instead of all users. – Waldir Leoncio Feb 21 '14 at 18:10