2

On Windows, in my RProfile.site, I used to set:

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

However, this does not create the same effect on Ubuntu. Any ideas on how I can achieve the same effect? Such that when I type ~ in a path it expands to R_USER?

Here's an example. On Windows, after setting R_USER, in my scripts I would use the following:

read.csv("~/Project") 

Where "~" expanded to /some/path/to/projects/

Brandon Bertelsen
  • 43,807
  • 34
  • 160
  • 255

1 Answers1

4

Define HOME="/my/projects/folder", preferably for R only, in .Renviron

Functionality for changing the method of ~ path expansion on windows does not exist in the same fashion as Windows as it does in Ubuntu/Linux*

Brandon Bertelsen
  • 43,807
  • 34
  • 160
  • 255
Dirk Eddelbuettel
  • 360,940
  • 56
  • 644
  • 725
  • I have all my project files in the same directory and I'd like R to start looking there. So when I type ~/ it expands to /my/projects/folder/ – Brandon Bertelsen Jul 12 '12 at 21:08
  • Define HOME="/my/projects/folder", preferably for R only, in `.Renviron`. – Dirk Eddelbuettel Jul 12 '12 at 21:14
  • I added this line to /etc/R/Rpofile.site - didn't seem to have any effect. Was it supposed to be defined somewhere else? – Brandon Bertelsen Jul 12 '12 at 21:16
  • See `help(Startup)` which needs several paragraphs to explain this. I can't beat that in 200 chars... [ It might be that you cannot override HOME, dunno... ] – Dirk Eddelbuettel Jul 12 '12 at 21:19
  • Didn't notice that you specified ".Renviron". Thanks for that. – Brandon Bertelsen Jul 12 '12 at 21:31
  • That worked for path.expand("~"), but it seems to have changed other things as well (like the path to my packages). – Brandon Bertelsen Jul 12 '12 at 21:34
  • Of course. $HOME is used for many things. Personally, I would just do `ln -s /my/path/to/projects ~/proj` and from there on refer to `~/proj/...`. But you asked for an override of `~` (== `$HOME`) and now you got to live with the consequences ;-) – Dirk Eddelbuettel Jul 12 '12 at 21:36
  • In Windows, setting R_USER, made the tilde function as a call to path/to/proj/ is this not possible in ubuntu? – Brandon Bertelsen Jul 12 '12 at 21:39
  • 1
    [This says](http://cran.r-project.org/bin/windows/base/rw-FAQ.html#What-are-HOME-and-working-directories_003f): "If environment variable R_USER is set, its value is used. Otherwise if environment variable HOME is set, its value is used". However, I find that `$HOME=/home/garrett/tmp R --slave -e 'print(path.expand("~"))'` works, but `$R_USER=/home/garrett/tmp R --slave -e 'print(path.expand("~"))'` does not – GSee Jul 12 '12 at 21:47
  • @GSee: But aren't you quoting from the R-on-Windows FAQ trying to infer behaviour on Ubuntu? The two OS and implementations are sometimes different, see the R sources... – Dirk Eddelbuettel Jul 12 '12 at 21:49
  • Haha. Oops. Good catch @DirkEddelbuettel – GSee Jul 12 '12 at 21:50
  • @BrandonBertelsen: And I surmise this also covers your Q. Just because it works on Windoze... – Dirk Eddelbuettel Jul 12 '12 at 21:52
  • Yeah, "Not possible". Sad panda. – Brandon Bertelsen Jul 13 '12 at 12:12
  • I'm not a programmer. In my eyes, C++ is the enemy. Maybe I can bust out the old "Structured C for Engineering" textbook from first year? HA. – Brandon Bertelsen Jul 13 '12 at 12:22