3

Somehow, my home and library directories in R got changed to a cloud location, which is messing up a bunch of paths, and now, I can't seem to change it back. When I type path.expand("~") in R, I get back "C:/Users/MyName/OneDrive/Documents", but I was expecting to get "C:/Users/MyName/Documents".

When I try .libPaths(), I get "C:/Users/MyName/OneDrive/Documents/R/win-library/3.4" and "C:/Program Files/R/R-3.4.3/library", but I only want the latter.

I have tried uninstalling and reinstalling both R and RStudio (thus now working with the most-recent versions of each), but the cloud path persists. I have seen posts elsewhere on SO about setting things in the .Rprofile file, but I don't think that's the right option, especially since the .Rprofile file would then have to be in a cloud location, which I don't want.

I have looked at my environment variables in the control panel (I'm on Windows 10) and looked at PATH, but there's nothing there that specifies the cloud directory, so I don't know where it's coming from.

How do I permanently change my home directory and also make sure that .libPaths is pointing to only the actual library directory?

shirewoman2
  • 1,842
  • 4
  • 19
  • 31

2 Answers2

4

This is based on your windows environment variable HOME. You need to reset HOME to the path that you want "C:/Users/MyName/Documents"

If you want to do that from within R, you can use:

Sys.setenv(HOME="C:/Users/MyName/Documents")

This change would not be permanent. If you wish to avoid doing this every time you run R, you could put the above statement in your .Rprofile file. There is a nice article on setting up your .Rprofile in the RStudio support

G5W
  • 36,531
  • 10
  • 47
  • 80
4

Since you mention you are

  • in Windows 10
  • you can also set the R Home Directory just for R without changing your system HOME with a special environment variable,

    R_USER

Adding this to your Environment Variables with the path you want for your R Home will set the R Home path without changing your system HOME.
RStudio looks for R_USER first (and then moves on to HOME).

Mike M
  • 1,382
  • 11
  • 23
  • 1
    Thank you. I followed [these instructions](https://support.shotgunsoftware.com/hc/en-us/articles/114094235653-Setting-global-environment-variables-on-Windows) to add R_USER to my environment variables. – billiam Jan 13 '21 at 19:17
  • great :) Yes, that is an important piece of the puzzle ~ – Mike M Jan 13 '21 at 22:02