简体   繁体   中英

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!

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.

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.

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:-

  1. go to session in nav bar -> clear workspace.
  2. go to session in nav bar -> restart R then the update.packages() worked.

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.

If you are working in RStudio on Windows:

  • 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 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM