Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Installing package - cannot open file - permission denied

I'm working in RStudio and am attempting to install the dplyr package. I have installed various other packages without problem but have hit a problem with this.

It seems there are various parts to the install, some of these worked but the problem happens when I get 'the dependency BH'. This is the error:

>Installing package into ‘\\xxxxxxxx.local/Desktops/jagnew/My Documents/R/win-library/3.3’
    (as ‘lib’ is unspecified)
    also installing the dependency ‘BH’
    
>trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.3/BH_1.62.0-1.zip'
    Content type 'application/zip' length 16150075 bytes (15.4 MB)
    downloaded 15.4 MB
    
>trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.3/dplyr_0.5.0.zip'
    Content type 'application/zip' length 2556205 bytes (2.4 MB)
    downloaded 2.4 MB
    
>Error in install.packages : cannot open file '\\xxxxxxx.local/Desktops/jagnew/My Documents/R/win-library/3.3/file142032c9327b/BH/include/boost/function/detail/gen_maybe_include.pl': Permission denied

I have changed the directory/libpath as it did not appear that the file was downloading to the correct folder. file142032c9327b is now in the correct path, but path specified in the error is only correct up to /boost, there is no function folder here..?

I'm not sure if this missing folder is the issue, as the error says 'Permission denied', but it seems odd.

like image 414
agwah Avatar asked Mar 15 '17 10:03

agwah


People also ask

Can install packages in R Permission denied?

If R (or RStudio with R) was installed as administrator in Windows and you try to install or update a package you lack of permissions. Either run the installation as admin or avoid the installation as admin.

Do you want to restart R prior to installing?

Restarting R prior to updating these packages is strongly recommended. RStudio can restart R and then automatically continue the installation after restarting (all work and data will be preserved during the restart).


Video Answer


4 Answers

I had the same issue. Tried doing the following and worked for me:

  1. Run the RStudio as administrator
  2. Under the Packages tab, click Install and change Install to Library option to C:/Program...../R/../library and select the desired package to install.

enter image description here

Hope it works.

like image 78
Shubham Yadav Avatar answered Oct 16 '22 19:10

Shubham Yadav


I had the same problem. R gave me an error message whenever I tried to install a new, or update an existing package. I don't remember what the message said exactly, but it was saying "Cannot open file (...) access denied". I tried all the following. Not sure what exactly fixed the problem, but now I can update and/or install new packages:

  1. Open R/RStudio as administrator;
  2. Change the R library folder (where packages are installed) security settings, and grant full access to my computer user account. Link1, link2;
  3. (I think this was what fixed the problem) Follow instructions on this link. It prompted me to install another package, "devtools". Then it worked.
like image 20
SenshiKudo Avatar answered Oct 16 '22 19:10

SenshiKudo


Well, I think my problem was a special case, but it might benefit someone. I had the Windows Defender Ransomware Protection set to ON. That was blocking rsession.exe by default. Allowing rsession.exe solved the problem.

like image 3
Rami Alloush Avatar answered Oct 16 '22 20:10

Rami Alloush


TL;DR

The "Documents" (or "My Documents") directory is a special location in Windows. I don't know if the system itself processes its permissions differently or if antiviruses target operations inside this directory more strictly, but many R users have issues installing packages in the personal library inside this folder (even if running R as administrator). Other answers haven't worked.

For me, what solved the problem was to put the personal library directly under X:\\Users\username\ instead of under Documents, which is the R default on Windows. To make it permanent, I set a user environment variable R_USER to %USERPROFILE%. Here is a nice guide of how to set environment variables in Windows.

Note: after this change, you may need to move your .Rprofile, .Renviron, etc. files from Documents to the user profile directory.


Details

The default location for R's user "home" directory on Windows is X:\\Users\username\Documents. This is because there is no concept of HOME in Windows, just of a "personal" directory (Documents): https://cran.r-project.org/bin/windows/base/rw-FAQ.html#What-are-HOME-and-working-directories_003f

Therefore, by default, the personal library location is under X:\\Users\username\Documents\R\win-library\X.Y\. You can get the exact location on your machine with this command in the R console:

Sys.getenv('R_LIBS_USER')

I was getting this same cannot open file error when trying to install or update packages, even when running as administrator. I suspected of directory permissions, checked it within the directories' "properties" without luck. Removed the whole R\win-library tree and recreated it and nothing... Finally, I tried to move the personal library location to my users' directory:

.libPaths('X://Users/username/R/win-library/X.Y/')

And it worked!

like image 2
leogama Avatar answered Oct 16 '22 18:10

leogama