Error in installation a R package
RInstallationPackageR Problem Overview
Please help me, I cannot install "MASS" package.
> library(MASS)
Error in library(MASS) : there is no package called ‘MASS’
I tried to install MASS package from local:
> utils:::menuInstallLocal()
package ‘MASS’ successfully unpacked and MD5 sums checked
Warning: cannot remove prior installation of package ‘MASS’
Even I cannot remove "MASS":
> remove.packages("MASS")
Removing package from ‘C:/Program Files/R/R-3.0.1/library’
(as ‘lib’ is unspecified)
Error in find.package(pkgs, lib) : there is no package called ‘MASS’
Also with this option I couldn't install package:
> options(install.lock=T)
> utils:::menuInstallLocal()
package ‘MASS’ successfully unpacked and MD5 sums checked
Warning: cannot remove prior installation of package ‘MASS’
Warning: restored ‘MASS’
Warning message:
In file.copy(savedcopy, lib, recursive = TRUE) :
problem copying C:\Program Files\R\R-3.0.1\library\00LOCK\MASS\libs\x64\MASS.dll to C:\Program Files\R\R-3.0.1\library\MASS\libs\x64\MASS.dll: Permission
And with install.packages:
> install.packages("C:\\MASS_7.3-35.zip",repos=NULL)
package ‘MASS’ successfully unpacked and MD5 sums checked
Warning: cannot remove prior installation of package ‘MASS’
Warning: restored ‘MASS’
Warning message:
In file.copy(savedcopy, lib, recursive = TRUE) :
problem copying C:\Program Files\R\R-3.0.1\library\00LOCK\MASS\libs\x64\MASS.dll to C:\Program Files\R\R-3.0.1\library\MASS\libs\x64\MASS.dll: Permission
I should mention I use R with ORE (Oracle R Enterprise).
R Solutions
Solution 1 - R
There could be a few things happening here. Start by first figuring out your library location:
Sys.getenv("R_LIBS_USER")
or
.libPaths()
We already know yours from the info you gave: C:\Program Files\R\R-3.0.1\library
I believe you have a file in there called: 00LOCK
. From ?install.packages
:
> Note that it is possible for the package installation to fail so badly that the lock directory is not removed: this inhibits any further installs to the library directory (or for --pkglock, of the package) until the lock directory is removed manually.
You need to delete that file. If you had the pacman
package installed you could have simply used p_unlock()
and the 00LOCK
file is removed. You can't install pacman
now until the 00LOCK
file is removed.
To install pacman
use:
install.packages("pacman")
There may be a second issue. This is where you somehow corrupted MASS
. This can occur, in my experience, if you try to update a package while it is in use in another R session. I'm sure there's other ways to cause this as well. To solve this problem try:
- Close out of all R sessions (use task manager to ensure you're truly R session free) Ctrl + Alt + Delete
- Go to your library location
Sys.getenv("R_LIBS_USER")
. In your case this is: C:\Program Files\R\R-3.0.1\library - Manually delete the
MASS
package - Fire up a vanilla session of R
- Install
MASS
viainstall.packages("MASS")
If any of this works please let me know what worked.
Solution 2 - R
I had the same problem with e1071 package. Just close any other R sessions running parallelly and you will be good to go.
Solution 3 - R
In my case, the installation of nlme
package is in trouble:
mv: cannot move '/home/guanshim/R/x86_64-pc-linux-gnu-library/3.4/nlme'
to '/home/guanshim/R/x86_64-pc-linux-gnu-library/3.4/00LOCK-nlme/nlme':
Permission denied
Using Ubuntu 18.04, CTRL+ALT+T to open a terminal window:
sudo R
install.packages('nlme')
q()
Solution 4 - R
The solution indicated by Guannan Shen has one drawback that usually goes unnoticed.
When you run sudo R
in order to run install.packages()
as superuser, the directories in which you install the library end up belonging to root
user, a.k.a., the superuser.
So, next time you need to update your libraries, you will not remember that you ran sudo
, therefore leaving root
as the owner of the files and directories; that eventually causes the error when trying to move files, because no one can overwrite root
but themself.
That can be averted by running
sudo chown -R yourusername:yourusername *
in the directory lib
that contains your local libraries, replacing yourusername
by the adequated value in your installation. Then you try installing once again.
Solution 5 - R
After using the wrong quotation mark characters in install.packages()
, correcting the quote marks yielded the "cannot remove prior installation" error. Closing and restarting R worked.
Solution 6 - R
In my case, I had to close R session and reinstall all packages. In that session I worked with large tables, I suspect this might have had the effect.
Solution 7 - R
I just wanted to add my own experience with this error.
I recently updated R using installR
within the RGui as recommended but during the installation process, the GUI froze.
When I launched RStudio the next time to get some work done, most of my packages needed to be manually deleted and re-installed. Seems they did not get moved over.
Hope this helps someone in the future.
Solution 8 - R
I faced a similar situation and received the following error while creating a new RMD file in Rstudio: > Package 'xfun' successfully installed. Warning message: In file.copy(savedcopy, lib, recursive = TRUE) : problem copying C:\Users<computername>\Documents\R\win-library\3.6\00LOCK\xfun\libs\x64\xfun.dll to C:\Users<computername>\Documents\R\win-library\3.6\xfun\libs\x64\xfun.dll: Permission denied
Because it was facing an issue while overwriting on top of the file, I simply pasted the older file elsewhere and it was able to create a new one while installing at the location above. >package 'xfun' successfully unpacked and MD5 sums checked > The downloaded binary packages are in C:\Users<computername>\AppData\Local\Temp\Rtmpq0b4WV\downloaded_packages