R package installation error: "cannot remove earlier installation"

Viewed 210

I'm currently making a R package (tessellation) which includes some C code. When I do some modifications and click "Install and restart" in RStudio, I get this error:

==> Rcmd.exe INSTALL --no-multiarch --with-keep.source tessellation

* installing to library 'C:/PortableApps/R/R-4.1.2/App/R-Portable/library'
* installing *source* package 'tessellation' ...
ERROR: cannot remove earlier installation, is it in use?

When I do "Restart R session" before "Install and restart", sometimes this works, sometimes not. So I have to close the project and reopen it, and this is annoying. Do you know what could I do to work more conveniently?

1 Answers

You need to be sure that the process is not being used (or loaded into R's search path) for the package. I suggest stopping all R sessions, deleting the installed package folder manually, start an R vanilla session, check the attached packages/search path, and finally attempt re-installation/building the package:

# from terminal
R --vanilla

# check search path
ls()
search()

# attempt installing package
devtools::install() # or devtools::build()
Related