installation path not writable R, unable to update packages - r

I am trying to install Bioconductor into R, using the code on their website. When I type in the code (see bellow) I get an error message saying that some packages can't be updated, the installation path is unwriteable.
> ## try http:// if https:// URLs are not supported
> source("https://bioconductor.org/biocLite.R")
Bioconductor version 3.4 (BiocInstaller 1.24.0), ?biocLite for help
> biocLite()
BioC_mirror: https://bioconductor.org
Using Bioconductor 3.4 (BiocInstaller 1.24.0), R 3.3.2 (2016-10-31).
installation path not writeable, unable to update packages: Matrix, mgcv,
survival
I can install these package by going to packages/install packages.
> utils:::menuInstallPkgs()
trying URL 'https://www.stats.bris.ac.uk/R/bin/windows/contrib/3.3/Matrix_1.2-8.zip'
Content type 'application/zip' length 2775038 bytes (2.6 MB)
downloaded 2.6 MB
trying URL 'https://www.stats.bris.ac.uk/R/bin/windows/contrib/3.3/mgcv_1.8- 16.zip'
Content type 'application/zip' length 2346257 bytes (2.2 MB)
downloaded 2.2 MB
trying URL 'https://www.stats.bris.ac.uk/R/bin/windows/contrib/3.3/survival_2.40-1.zip'
Content type 'application/zip' length 5109948 bytes (4.9 MB)
downloaded 4.9 MB
package ‘Matrix’ successfully unpacked and MD5 sums checked
package ‘mgcv’ successfully unpacked and MD5 sums checked
package ‘survival’ successfully unpacked and MD5 sums checked
The downloaded binary packages are in
C:\Users\stxeb8\AppData\Local\Temp\Rtmp2tQZ4v\downloaded_packages
I can then go to packages/ load packages and load them succesfully and search and see that the packages are there.
> local({pkg <- select.list(sort(.packages(all.available = TRUE)),graphics=TRUE)
+ if(nchar(pkg)) library(pkg, character.only=TRUE)})
Loading required package: nlme
This is mgcv 1.8-16. For overview type 'help("mgcv-package")'.
> local({pkg <- select.list(sort(.packages(all.available = TRUE)),graphics=TRUE)
+ if(nchar(pkg)) library(pkg, character.only=TRUE)})
> local({pkg <- select.list(sort(.packages(all.available = TRUE)),graphics=TRUE)
+ if(nchar(pkg)) library(pkg, character.only=TRUE)})
> local({pkg <- select.list(sort(.packages(all.available = TRUE)),graphics=TRUE)
+ if(nchar(pkg)) library(pkg, character.only=TRUE)})
> search()
[1] ".GlobalEnv" "package:survival" "package:mgcv"
[4] "package:nlme" "package:Matrix" "package:BiocInstaller"
[7] "package:stats" "package:graphics" "package:grDevices"
[10] "package:utils" "package:datasets" "package:methods"
[13] "Autoloads" "package:base"
But then when I go to install bioconductor it gives me the same error message that Matrix, mgcv and survival aren't able to be updated.
> ## try http:// if https:// URLs are not supported
> source("https://bioconductor.org/biocLite.R")
Bioconductor version 3.4 (BiocInstaller 1.24.0), ?biocLite for help
> biocLite()
BioC_mirror: https://bioconductor.org
Using Bioconductor 3.4 (BiocInstaller 1.24.0), R 3.3.2 (2016-10-31).
installation path not writeable, unable to update packages: Matrix, mgcv,
survival
What can I do to be able to update these packages so I can install bioconductor?

In general, I would advise against changing the permission in system folders, because R should work without additional administrative rights.
Thus I would likewise advise against installing packages using administrative rights, as you would be required to do so in the future every time you have to update these packages!
To backtrace this issue and prevent to minimize it in future updates, you should perform the following steps:
Note which packages that fail to update (already shown in the error message).
Locate the folders where all R packages are installed using .libPaths(). This should provide two results, a destination in your home folder and a system folder.
"/home/USER/R/x86_64-pc-linux-gnu-library/X.X" "/usr/lib/R/library"
Install the packages with install.packages(c("PKG1", "PKG2", "PKG3")) or BiocManager::install(c("PKG1", "PKG2", "PKG3"))*
Only If you have administrator rights: Manually remove the older package folders from the system folder ("/usr/lib/R/library"), using administrator rights (sudo) OR enter R with administrator rights One last time and run remove.packages(c("PKG1", "PKG2", "PKG3"), lib = "/usr/lib/R/library").
*If there are issues with the installation path, add the argument , lib = "/home/USER/R/x86_64-pc-linux-gnu-library/X.X" to either of the install functions in step 3. This argument explicitly states to install in your home folder.
There is a single issue with this approach, at least with the official R repository on Arch Linux: Whenever R is updated, the updated version still includes packages in the system folder, that can't be updated without administrative rights. Therefore for each R update, this procedure must be repeated. I'm especially looking at you survival!!!
*Edit: It is important to note that biocLite is no longer the recommended tool for installing BioConductor packages. You should instead use BiocManager, which is in the official CRAN repository (install.packages("BiocManager")).
**Second edit: As this answer still receives votes, I have updated and cleaned up the answer.

It was a permission issue for me. First, I identified where the packages were installed using installed.packages()[, c("Package", "LibPath")]. This outputs a long 2 column matrix with the names and locations of the packages. Then you will see where the offending packages are. In my case, they were at /usr/lib/R/site-library and /usr/lib/R/library. Then I changed the permission of these folders by chmod (I used chmod -R 777 on the main R folder, this is my personal computer, so security is not a big concern here I think).

If you are running R/Rstudio on Windows, then just open R/Rstudio as administrator. Right click on the icon then run as administrator

It looks like several 'recommended' packages are installed in two places -- maybe by an administrator account in a directory you don't have write access to, and then by RStudio in a directory where you do have write access. biocLite() is complaining about the former.
Unless biocLite() complains about a Bioconductor package that cannot be installed (different from cannot be updated), there is no problem and basic Bioconductor packages have been successfully installed. Check out https://support.bioconductor.org for future Bioconductor-related support.

One solution is to open a terminal and load R using admin rights
sudo R
update.packages()
source("https://bioconductor.org/biocLite.R")
biocLite()
Then you can update. But careful. This can create packages by the admin in a directory supposed to be owned by a user.
In this case, instead of loading R as root (which is solving the problem until the next update), check the .libPaths(). You will have a list of directories.
.libPaths()
"/home/it_s_me/R/x86_64-pc-linux-gnu-library/3.4" "/usr/lib/R/library"
In my case, all packages in "/usr/lib/R/library" are owned by root, and all except one are owned by a normal user (not root) at "/home/itsame/R/x86_64-pc-linux-gnu-library/3.4".
If you have admin rights, an easy solution may be to run chown in all the places: For example, I had trouble updating the curl package. I used:
sudo chown -R it_s_me /home/it_s_me/R/x86_64-pc-linux-gnu-library/3.4/curl/

I had a similar problem with other Bioconductor packages and the solution was simpler than I thought. I had to install some OS packages pointed out on my log: libcurl-dev, libcurl4-openssl-dev, libssl-dev.
My advice is to check your R log and look for "Configuration failed because [PACKAGE] was not found. Try installing".

Since with the version of R 3.6.1 the script http://bioconductor.org/biocLite.R returns this message " Error: With R version 3.5 or greater, install Bioconductor packages using BiocManager; see https://bioconductor.org/install " I solved the problem with the following steps:
Get the list of directories used by R to install libraries and
choose the one with write permissions using: .libPaths()
Installing the "BiocManager" library using: install.packages("BiocManager")
Installation of the library "bioconductor" by forcing the directory
with write permissions using: BiocManager::install("Rgraphviz", lib = "C:/Users/tizbet/Documents/R/win-library/3.6")
I worked on the following R installation:
platform x86_64-w64-mingw32, arch x86_64, os mingw32, system x86_64, mingw32, version.string R version 3.6.1 (2019-07-05)
I was inspired by the Kasper Thystrup Karstensen answer

Whenever you want to work on an R-code where packages need to be installed: -
Windows: Open R-studio as 'Run as administrator' [Right click on the icon]
Linux: Run as sudo user; else get writing rights from the administrator

Ubuntu:
sudo apt install libcurl-dev
Fedora:
sudo dnf install libcurl-devel

Related

Tidyverse in R: Cannot load package [duplicate]

I attempted install.packages("RMySQL") and it runs for a second and then says:
Error in install.packages : cannot remove prior installation of package ‘DBI’
I did remove.packages("DBI") and it says:
remove.packages("DBI")
Removing package from ‘/Library/Frameworks/R.framework/Versions/3.2/Resources/library’
(as ‘lib’ is unspecified)
Then I retry install.packages("RMySQL") and it says:
Error in install.packages : cannot remove prior installation of package ‘DBI’
The DBI dependency is not actually getting removed or something. Or possibly I removed it from the wrong area? I'm confused.
Try starting R without any startup files to prevent DBI from being loaded (however that happens on your box).
You should then be able to just delete the unattached package.
Alternatively, just remove the DBI/ directory from library directory.
It should look similar to this:
$ R --vanilla ## prevent inits at load
R version 3.4.1 (2017-06-30) -- "Single Candle"
Copyright (C) 2017 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
Natural language support but running in an English locale
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> ls() ## no variables
character(0)
> search() ## no packages besides Base
[1] ".GlobalEnv" "package:stats" "package:graphics"
[4] "package:grDevices" "package:utils" "package:datasets"
[7] "package:methods" "Autoloads" "package:base"
>
I had that same problem with package 'rlang', while trying to reinstall it would present me the error: "Error in install.packages : cannot remove prior installation of package ‘rlang’ "
The problem here is that the old installation is not totally gone.
When that happens just look for the location where you have your packages installed (use the command .libPaths() in R console) , then look for a directory that has a name that is not a regular name included in installed packages, that is the folder that needs to be removed.
After removing that old installation folder you are ready to reinstall the package again, it worked for me, hope it helps!
Go to the R library that has all the packages folder and delete the particular package folder that you want to uninstall and then again try installing. Mere removing the packages with remove.package is not going to work.
Check your task manager for R related programs running in the background, I had files open from "microsoft.r.host.broker.exe" preventing me from accessing or deleting them. Closing it fixed the problem.
I've met the same problem. And I tried to restart R or RStudio, it just happened again.
Then I realized when I restarted the RStudio, it loaded previous data all the time because I saved the .Rdata and .Rhistory file in my workspace (working directory).
I deleted the two files and tried again to restart and reinstall, it worked. Maybe it's helpful if you are in the same situation.
first clear the environment so that the packages are not loaded:-
go to session in nav bar -> clear workspace.
go to session in nav bar -> restart R
then the update.packages() worked.
If you are working in RStudio:
First update all your installed packages using RStudio toolbar -> Tools -> Check for package updates.
Try installing your package again.
For me this resolved the warning 'cannot remove prior installation of package...' when trying to update (=reinstall) a previously installed R package from a GitHub repository.
I also had this issue, and no matter how many times I restarted R or terminated R, tried to delete the package file, or terminated R processes, I could not install the package (in my case, openxlsx).
Finally, I ended up restarting my PC, creating a new project that would serve as a "throwaway", called install.packages(), and that did the trick.
I reinstalled R 4.0.1 and packages again after removing R and its libraries completely
sudo rm -rf /Library/Frameworks/R.framework /Applications/R.app \
/usr/bin/R /usr/bin/Rscript
It worked
On Windows 10 and R version 3.6.3
I don't know how many times I've had this problem, solved it, and forgotten how until the next time it occurs. I have been revisiting this post SO many times by now.. This time, the following solved my problem:
Delete .Rhistory and .RData as suggested by #Marcus LCC and restart the computer.
I then tried to install my package again, with the error code:
devtools::install_github("hrbrmstr/nominatim")
Error in loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]]) :
there is no package called ‘rlang’
So I installed rlang (despite having it installed already), and installed my desired package again. (Note that I never deleted rlang, only .rHistory and .rData)
Worked for me, hope it helps someone! :)
change permission to all the folders in
'/Library/Frameworks/R.framework/Versions/3.2/Resources/library'
run the install.packages
once installed restore permissions

Installing sleuth using Bioconductor, error where the path is not writable?

I'm having trouble installing sleuth into R studio. I have already tried troubleshooting using the suggested methods in a stockoverflow titled "installation path not writable R, unable to update packages" (link: installation path not writable R, unable to update packages). I keep getting the following error.
Error Message:
Bioconductor version 3.10 (BiocManager 1.30.10), R 3.6.1 (2019-07-05)
Installation path not writeable, unable to update packages: boot, class, foreign, KernSmooth, lattice,
MASS, Matrix, mgcv, nlme, nnet
Old packages: 'isoband', 'purrr', 'RcppArmadillo', 'RCurl', 'reshape2', 'survival'
Update all/some/none? [a/s/n]:
BiocManager::install("devtools") # only if devtools not yet installed
Update all/some/none? [a/s/n]:
BiocManager::install("pachterlab/sleuth")
Update all/some/none? [a/s/n]:
When I type in this code:
if (!requireNamespace("BiocManager", quietly = TRUE))
install.packages("BiocManager")
BiocManager::install()
BiocManager::install("devtools") # only if devtools not yet installed
BiocManager::install("pachterlab/sleuth")
Thank you for your help!
This answer might be helpful.
It looks like the offending packages (boot, class, foreign, etc.) are installed in a location where you do not have writing permissions for.
In principle, the sleuth package should have been installed, despite the error messages (you can check this by running library(sleuth) in an R console). However, to avoid having these errors each time you try installing a (BioConductor) package, I would recommend to re-install those offending packages in a directory where you have writing access to. Depending on your OS this can be in different locations.
I found this guide particularly useful to maintain R packages.
In short (all commands are run in R):
Remove the packages mentioned in the error message with remove.packages(), if sleuth was installed, remove it as well, we will install it again later in a more maintainable way
In R, check the output of Sys.getenv("R_LIBS_USER"), this should normally be a directory path under your home directory
It's likely that the R_LIBS_USER directory does not yet exist, create it with dir.create(Sys.getenv("R_LIBS_USER"))
Restart R (in RStudio, you can do Session → Restart R
Check the output of .libPaths(), the first element should now be the directory you just created (i.e. the same as Sys.getenv("R_LIBS_USER")), this is now the default directory where R packages will be installed
Install sleuth again with BiocManager::install("pachterlab/sleuth"), this should normally also install all dependencies. If not you might have to install them separately.
Hope this helps!

Error in install.packages : cannot remove prior installation of package ‘DBI’

I attempted install.packages("RMySQL") and it runs for a second and then says:
Error in install.packages : cannot remove prior installation of package ‘DBI’
I did remove.packages("DBI") and it says:
remove.packages("DBI")
Removing package from ‘/Library/Frameworks/R.framework/Versions/3.2/Resources/library’
(as ‘lib’ is unspecified)
Then I retry install.packages("RMySQL") and it says:
Error in install.packages : cannot remove prior installation of package ‘DBI’
The DBI dependency is not actually getting removed or something. Or possibly I removed it from the wrong area? I'm confused.
Try starting R without any startup files to prevent DBI from being loaded (however that happens on your box).
You should then be able to just delete the unattached package.
Alternatively, just remove the DBI/ directory from library directory.
It should look similar to this:
$ R --vanilla ## prevent inits at load
R version 3.4.1 (2017-06-30) -- "Single Candle"
Copyright (C) 2017 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
Natural language support but running in an English locale
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> ls() ## no variables
character(0)
> search() ## no packages besides Base
[1] ".GlobalEnv" "package:stats" "package:graphics"
[4] "package:grDevices" "package:utils" "package:datasets"
[7] "package:methods" "Autoloads" "package:base"
>
I had that same problem with package 'rlang', while trying to reinstall it would present me the error: "Error in install.packages : cannot remove prior installation of package ‘rlang’ "
The problem here is that the old installation is not totally gone.
When that happens just look for the location where you have your packages installed (use the command .libPaths() in R console) , then look for a directory that has a name that is not a regular name included in installed packages, that is the folder that needs to be removed.
After removing that old installation folder you are ready to reinstall the package again, it worked for me, hope it helps!
Go to the R library that has all the packages folder and delete the particular package folder that you want to uninstall and then again try installing. Mere removing the packages with remove.package is not going to work.
Check your task manager for R related programs running in the background, I had files open from "microsoft.r.host.broker.exe" preventing me from accessing or deleting them. Closing it fixed the problem.
I've met the same problem. And I tried to restart R or RStudio, it just happened again.
Then I realized when I restarted the RStudio, it loaded previous data all the time because I saved the .Rdata and .Rhistory file in my workspace (working directory).
I deleted the two files and tried again to restart and reinstall, it worked. Maybe it's helpful if you are in the same situation.
first clear the environment so that the packages are not loaded:-
go to session in nav bar -> clear workspace.
go to session in nav bar -> restart R
then the update.packages() worked.
If you are working in RStudio:
First update all your installed packages using RStudio toolbar -> Tools -> Check for package updates.
Try installing your package again.
For me this resolved the warning 'cannot remove prior installation of package...' when trying to update (=reinstall) a previously installed R package from a GitHub repository.
I also had this issue, and no matter how many times I restarted R or terminated R, tried to delete the package file, or terminated R processes, I could not install the package (in my case, openxlsx).
Finally, I ended up restarting my PC, creating a new project that would serve as a "throwaway", called install.packages(), and that did the trick.
I reinstalled R 4.0.1 and packages again after removing R and its libraries completely
sudo rm -rf /Library/Frameworks/R.framework /Applications/R.app \
/usr/bin/R /usr/bin/Rscript
It worked
On Windows 10 and R version 3.6.3
I don't know how many times I've had this problem, solved it, and forgotten how until the next time it occurs. I have been revisiting this post SO many times by now.. This time, the following solved my problem:
Delete .Rhistory and .RData as suggested by #Marcus LCC and restart the computer.
I then tried to install my package again, with the error code:
devtools::install_github("hrbrmstr/nominatim")
Error in loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]]) :
there is no package called ‘rlang’
So I installed rlang (despite having it installed already), and installed my desired package again. (Note that I never deleted rlang, only .rHistory and .rData)
Worked for me, hope it helps someone! :)
change permission to all the folders in
'/Library/Frameworks/R.framework/Versions/3.2/Resources/library'
run the install.packages
once installed restore permissions

Installation of RQuantLib

I tried to install RQuantLib from RStudio, but it has given me problems.
I updated my R version to 3.3.1 and tried to use the usual way of installing a package (install.packages("RQuantLib")) as recommended on the webpage of the author (http://dirk.eddelbuettel.com/code/rquantlib.html). However, it gave the following error message :
Warning in install.packages :
package ‘RQuantLib’ is not available (for R version 3.3.1)
I tried installing it on different computers too, but I got the same error message.
Does anyone else experience the same problem or has any idea what could have gone wrong? Thank you!
You are on Windows per your comment. As per this section of the README.md
Windows Binaries
Starting with release 0.4.3, binaries are provided via the ghrr drat repo and can be installed as
R> drat::addRepo("ghrr") # maybe use 'install.packages("drat")' first
R> install.packages(RQuantLib)
you can install a pre-built Windows binaries -- which I just updated for QuantLib 1.8.1 -- from this non-CRAN repo.
Edit: Apparently one now has to say type="binary" even on Windows. Here is a log from a virtual machine I keep:
R> drat::addRepo("ghrr")
R> options("repos")
$repos
CRAN ghrr
"https://cloud.r-project.org" "https://ghrr.github.io/drat/"
R> install.packages("RQuantLib", type="binary")
Installing package into c:/opt/R-library
(as lib is unspecified)
trying URL 'https://ghrr.github.io/drat/bin/windows/contrib/3.3/RQuantLib_0.4.3.zip'
Content type 'application/zip' length 7993848 bytes (7.6 MB)
downloaded 7.6 MB
package RQuantLib successfully unpacked and MD5 sums checked
The downloaded binary packages are in
C:\Users\[redacted]\AppData\Local\Temp\RtmpAHvBmo\downloaded_packages
R>
I'll update the README.md web page.

Confusion with .libPaths during package install

This will probably be answered by someone directing me to a help file but I'm clearly missing it thus far. My quandry is that when I install a package (sometimes), it does not appear to default to the contents of my .libPaths - instead it appears to want to install to a network path to which it does not have permission.
Here is my library path
>.libPaths()
[1] "C:/Program Files/R/R-3.3.0/library"
If I try to install this package without specifying the lib argument it seems like it is trying to save to a network folder (I have changed the name of the network drive in the error message but you get the idea):
> install.packages("rmarkdown")
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.3/rmarkdown_0.9.6.zip'
Content type 'application/zip' length 2182803 bytes (2.1 MB)
downloaded 2.1 MB
package ‘rmarkdown’ successfully unpacked and MD5 sums checked
The downloaded binary packages are in
C:\Users\my.name\AppData\Local\Temp\RtmpkFVHnn\downloaded_packages
Warning message:
In dir.create(configDir, recursive = TRUE) :
cannot create dir '\\server.name\server_directory', reason 'Permission denied'
However, if I specify .libpaths() in the "lib" argument, then it works. But isn't this the default to the lib argument?
> install.packages("rmarkdown",lib=.libPaths())
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.3/rmarkdown_0.9.6.zip'
Content type 'application/zip' length 2182803 bytes (2.1 MB)
downloaded 2.1 MB
package ‘rmarkdown’ successfully unpacked and MD5 sums checked
The downloaded binary packages are in
C:\Users\jordan.watson\AppData\Local\Temp\RtmpkFVHnn\downloaded_packages
This does not happen every time however. For example, I just loaded the "forecast" library no problem by simply writing install.packages("forecast").
I'd just like to understand this behavior better. Can someone explain why this is happening? I am on Windows 7 without full admin privileges - but I do have admin privileges to my R folder on the C drive.
Apologies in advance that I can not make a reproducible example - it's not really that type of question.
Jordan,
My feeling is your setup is incorrect.
Proposed Solution
Try running the following command and see if this fixes the situation.
Note: I have replaced my userid with <user> in the examples below.
.libPaths( c( "C:/Users/<user>/Documents/R/win-library/3.3", .libPaths()) )
Explanation
I would expect .libPaths() to return two directories not one by default.
> .libPaths()
[1] "C:/Users/<user>/Documents/R/win-library/3.3" "C:/Program Files/R/R-3.3.0/library"
When you install R it installs the base libraries under
C:/Program Files/R/R-3.3.0/library
any new libraries are normally added to:
"C:/Users/<user>/Documents/R/win-library/3.3"
if you type View(installed.packages()) you will be able to see where the packages are installed.
The packages that come with the R install (base, stats, and nearly 30 others) are stored in the library subdirectory of wherever you installed R. You can retrieve the location of this with:
> R.home("library")
[1] "C:/PROGRA~1/R/R-33~1.1/library"
> .Library
[1] "C:/PROGRA~1/R/R-33~1.1/library
You also get a user library for installing packages that will only be accessible by you. The location under Windows, for R version x.y.z, it is in the R/win-library/x.y subfolder of the home directory, where the home directory can be found via:
> path.expand("~")
[1] "C:/Users/<user>/Documents"
> Sys.getenv("HOME")
[1] "C:/Users/<user>/Documents"
Issue
Thus, I would expect .libPaths() to return two paths not one which implies that you have somehow misconfigured the R installation libpath.
I hope the above helps.
Refs:
https://stat.ethz.ch/R-manual/R-devel/library/base/html/libPaths.html
Learning R By: Richard Cotton

Resources