NonSleeper
NonSleeper

Reputation: 851

r - How to specify the path in normalizePath, or get around this error associated with it?

I'm learning R and just have it installed on my office computer. I don't have the administrator right on the computer (as I even have to call IT for installation).

Then I install a package. At first it doesn't work when typing, for example:

install.packages("thepackage")

The error message is this:

Error in normalizePath(path.expand(path), winslash, mustWork) : 
  path[1]="\\company\5050\Users\myusername\Documents\R\win-library\3.3": Access is denied
In addition: Warning message:
In normalizePath(path.expand(path), winslash, mustWork) :
  path[1]="\\company/5050/Users/myusername/Documents/R/win-library/3.3": Access is denied

I do some homework and find that a potential solution is to "Map a network drive to your network folder". I'm not sure what it means, but I try this:

install.packages("thepackage",lib="H:/Documents/R/win-library/3.3")

because it looks like I have more "control" of H drive (it has my username on it). And it works:

package ‘thepackage’ successfully unpacked and MD5 sums checked
The downloaded binary packages are in
    C:\Users\myusername\AppData\Local\Temp\Rtmp4MNURu\downloaded_packages

I then fail to load the package,

library(thepackage)

saying:

Error in normalizePath(path.expand(path), winslash, mustWork) : 
  path[1]="\\company/5050/Users/myusername/Documents/R/win-library/3.3": Access is denied

But again this works:

library(thepackage,lib="H:/Documents/R/win-library/3.3")

So how can I set the normalizePath to the one that works to avoid additional and rather unnecessary specification of library directory?

Upvotes: 14

Views: 48894

Answers (3)

GuiBridi
GuiBridi

Reputation: 13

I was with the same problem them I found this solution by the user Mike M.

In Windows 10/11 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).

It worked for me.

Upvotes: 0

Dominic Comtois
Dominic Comtois

Reputation: 10411

You can put in your home directory's .Rprofile file (just create it if it's not there yet) the following line:

.libPaths("H:/Documents/R/win-library/3.3")

That way this location will be used by default. The .Rprofile is run every time you're opening any new R session. You can copy the existing content of the folder from which you don't have write access to this folder to include all pre-installed packages.

Upvotes: 6

Konrad
Konrad

Reputation: 18595

I think you are looking for:

system("net use D: \\\\company\\path\\")

to map to the virtual D drive. I would then use file.path when accessing the stuff on D:. It looks that you may benefit from changing R defalut library path in Rprofile.site, by adding the line:

.libPaths("Path to your libs")

When you type .libPaths() can you read and write to that directory with no problems?

Upvotes: 3

Related Questions