0

whenever a new version update in many (not all packages) comes with a binary build i get this error :

* installing *source* package 'raster' ...
** package 'raster' successfully unpacked and MD5 sums checked
ERROR: cannot remove earlier installation, is it in use?
* removing 'C:/R/R-4.0.2/library/raster'
* restoring previous 'C:/R/R-4.0.2/library/raster'
Warning in file.copy(lp, dirname(pkgdir), recursive = TRUE, copy.date = TRUE) :
  problem copying C:\R\R-4.0.2\library\00LOCK-raster\raster\libs\x64\raster.dll to C:\R\R-4.0.2\library\raster\libs\x64\raster.dll: Permission denied
Warning in install.packages :
  installation of package ‘raster’ had non-zero exit status

i need a solution, please

thank you

is147
  • 118
  • 7
  • That's a Windows specific error, when the package is loaded and you want to install it. Try shutting down R and then running ```install.packages()``` as first command before doing anything else. – Julian_Hn Jul 18 '20 at 11:49
  • tried it already, does not work , thanks though for the suggestion! – is147 Jul 18 '20 at 11:55
  • check if you library contains folders with LOCK in their name and delete them. Sometimes Windows screws up the file lock and then the files can't be changed anymore. – Julian_Hn Jul 18 '20 at 11:59

1 Answers1

1

There can be more problems in that case. Try one of these:

  1. Maybe you need a really fresh session of R, i.e.:

    • click Session - Restart R in RStudio, without restoring the previous session,
    • or as @RobertHijmans mentions down in the comments, type unlink(".Rdata") in your R console and then exit R without saving your session and start R again without the nuisance of anything from a previous session getting loaded again.

    Then you can update all packages correctly.

  2. Or unload, detach(), raster package first:

    detach("package:raster", unload = TRUE)
    install.packages("raster")
    

    If that helps and problem occurs in more packages, you can use Detach all packages while working in R here on Stack Overflow.

  3. Or maybe you need to run R (or RStudio) as Administrator in Windows (right-click the file and choose that option, or find the file in Start menu and choose that option). I don't think it's your case as you have R library outside Program Files, but... things happen.

Run RStudio as admin

  • 1
    You can also do `unlink(".Rdata")` and exit R *without saving your session* and start R again without the nuisance of anything from a previous session getting loaded again. – Robert Hijmans Jul 18 '20 at 17:50
  • Thanks, @RobertHijmans, that's a good point, I have updated the answer with your suggestion! –  Jul 18 '20 at 19:29
  • does not work and if i uninstall the package completely i get this error when i try to install `Error in loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]]) : there is no package called 'raster' Calls: :: ... loadNamespace -> withRestarts -> withOneRestart -> doWithOneRestart Execution halted Warning in install.packages : installation of package ‘raster’ had non-zero exit status` – is147 Jul 19 '20 at 09:18
  • @IsmailMohsine Then try to manually delete folders `C:\R\R-4.0.2\library\00LOCK-raster` (if exists) and `C:\R\R-4.0.2\library\raster`, run RGui rather than RStudio and run `install.packages("raster")`. There are so many possible causes of this error that's hard to find the correct solution, but hope we'll find that! –  Jul 19 '20 at 10:22
  • there is no 00LOCK-raster folder , and when i removed the library completely then tried to reinstall it in Rgui i get the same message as i mentioned in my last comment – is147 Jul 20 '20 at 09:01