SUCKYPROGRAMMER
SUCKYPROGRAMMER

Reputation: 391

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.

Upvotes: 39

Views: 92307

Answers (12)

Pat Lorch
Pat Lorch

Reputation: 11

I keep an Rstudio project in my Documents folder that has nothing loaded into it. When I start Rstudio from there, no packages load. I can generally select all packages that need updating and update with no problem. This avoids trying to find the right folder to delete and restarting, as others have suggested.

Upvotes: 0

V. van Hees
V. van Hees

Reputation: 81

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.

Upvotes: 3

Lucio
Lucio

Reputation: 1

change permission to all the folders in '/Library/Frameworks/R.framework/Versions/3.2/Resources/library'

run the install.packages

once installed restore permissions

Upvotes: 0

HARSHITH
HARSHITH

Reputation: 79

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.

Upvotes: 5

chilifan
chilifan

Reputation: 195

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

Upvotes: 0

Efrain Plaza
Efrain Plaza

Reputation: 603

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!

Upvotes: 22

user2163234
user2163234

Reputation: 557

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.

Upvotes: 9

Marcus LCC
Marcus LCC

Reputation: 51

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.

Upvotes: 5

Singlecell
Singlecell

Reputation: 1

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

Upvotes: 0

sehock
sehock

Reputation: 399

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.

Upvotes: 1

Keerthana Karthik
Keerthana Karthik

Reputation: 101

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.

Upvotes: 10

Dirk is no longer here
Dirk is no longer here

Reputation: 368399

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

Upvotes: 25

Related Questions