Facing trouble in loading packages in R studio [duplicate] - r

I updated R using installr and asked to copy my library. (Even though I've never had this work, I keep hoping maybe it will someday as the package gets updated.) Opened up RStudio and, as usual, it can't find any of the packages that were in my old library. I next copied all the files from my old library into my new library, and several critical ones still don't work. For example, when I tried to load tidyverse, the message I receive is:
Error: package or namespace load failed for ‘tidyverse’: package ‘lazyeval’ was installed by an R version with different internals; it needs to be reinstalled for use with this R version.
I tried remove.packages("tidyverse") and then install.packages("tidyverse", dependencies = TRUE), and I still get the same message about the package lazyeval. I tried installing lazyeval, but then, when I go through those same steps again to try to use tidyverse, now it's lubridate that was installed by an R version with different internals.
How can I avoid this incredibly irritating and time-sucking iterative process of trying to install a package, seeing that the internals are wrong for some dependent package, installing whatever package was the problem, installing the package I actually care about, and then figuring out what other dependencies are problems?

The tidyverse package hardly contains anything: its main purpose is to get a bunch of other packages loaded. Removing it and updating it won't help update the other packages. You could do what #phago29 suggested in their comment, but an easier way is just to update everything. Run this command in an R session:
update.packages(ask = FALSE, checkBuilt = TRUE)
A few notes:
If you have admin capabilities, run as admin, and it will update your main library. If you don't, it'll install new copies in your user account.
Even though you're saying ask = FALSE, it may ask some questions about whether you can build packages from source. Answer "Yes" if your system is set up to do that, "No" if not. If you're not sure, try "Yes", and if you get install failures, run it again and say "No".)
This is likely to run for a while, so go away and have a coffee or something.

Related

Difficulty installing a package in R linux, dalton_rqi

Downloaded package from below URL.
Attempted to install using below command; response shown.
library(dalton.rqi,lib.loc='/home/X/Desktop/')
Error: package ‘dalton.rqi’ was built before R 3.0.0: please re-install it
https://my.clevelandclinic.org/departments/anesthesiology/depts/outcomes-research/risk-quantification
It appears this is a compiled package that maybe I don't have the source for? Is there a way to force install of the package? I'm unable to install using Rstudio GUI in its current form as a zip. Tried repackaging to tar.gz has Rstudio was looking for and also had a non-zero exit status error.
Any ideas?
I'm afraid this can't be achieved directly. The error message says it well: to use a package in R it needs to be built on an R version matching yours.
I can suggest two ways to move forward:
Contact the authors, ask for the R sources (it is somewhat surprising they did not make them available in the first place), and build the package yourself.
Downgrade your R version as far back as needed to match the one this pre-built package used.

After reinstalling R, I got error messenger to reinstall a bunch of packages one by one

I have recently reinstalled the R program (4.0.1 (2020-06-06)).
Ever since then, I got error messenger such as
Error: package or namespace load failed for ‘FlowSOM’:
package ‘pillar’ was installed before R 4.0.0: please re-install it
It tells me to install different packages one by one, like "pillar" above, so I have been re-installing them, and it's taking forever. With every loading action, I get the same multiple warnings.
I tried reinstalling R and RStudio. What else can I try?
After R upgrade there is sometimes necessary to rebuild installed packages with update.packages():
update.packages(ask = FALSE,
checkBuilt = TRUE)
That's because some packages need to be rebuild under a newer version of R. If you don't want to bother with this complications in the future, consider using installr package:
# for the first time
install.packages("installr")
# when you want to update R
installr::updateR()
This will update R and copy and rebuild all the packages for you.

Updated R, copied library, still can't find packages, and can't seem to install all dependencies

I updated R using installr and asked to copy my library. (Even though I've never had this work, I keep hoping maybe it will someday as the package gets updated.) Opened up RStudio and, as usual, it can't find any of the packages that were in my old library. I next copied all the files from my old library into my new library, and several critical ones still don't work. For example, when I tried to load tidyverse, the message I receive is:
Error: package or namespace load failed for ‘tidyverse’: package ‘lazyeval’ was installed by an R version with different internals; it needs to be reinstalled for use with this R version.
I tried remove.packages("tidyverse") and then install.packages("tidyverse", dependencies = TRUE), and I still get the same message about the package lazyeval. I tried installing lazyeval, but then, when I go through those same steps again to try to use tidyverse, now it's lubridate that was installed by an R version with different internals.
How can I avoid this incredibly irritating and time-sucking iterative process of trying to install a package, seeing that the internals are wrong for some dependent package, installing whatever package was the problem, installing the package I actually care about, and then figuring out what other dependencies are problems?
The tidyverse package hardly contains anything: its main purpose is to get a bunch of other packages loaded. Removing it and updating it won't help update the other packages. You could do what #phago29 suggested in their comment, but an easier way is just to update everything. Run this command in an R session:
update.packages(ask = FALSE, checkBuilt = TRUE)
A few notes:
If you have admin capabilities, run as admin, and it will update your main library. If you don't, it'll install new copies in your user account.
Even though you're saying ask = FALSE, it may ask some questions about whether you can build packages from source. Answer "Yes" if your system is set up to do that, "No" if not. If you're not sure, try "Yes", and if you get install failures, run it again and say "No".)
This is likely to run for a while, so go away and have a coffee or something.

How to update locally created R package without reinstalling

I created an R package using this tutorial. The package loads just fine when called but requires a bit debugging. After debugging my script, I used devtools::update_packages("new_package") to fix the changes, but I receive the following error: Skipping 1 packages not available: new_package (interestingly, new_package shows up when I call installed.packages()).
I'm able to update my package by reinstalling with devtools::install("new_package"), but for simple fixes this doesn't seem very efficient. Perhaps there is another way? I appreciate any help or insight.
EDIT for clarification:
I understand the package needs to be reloaded to update changes, but reloading the package using library(mypackage) (after detaching the package or starting a new session) does not accomplish this while devtools::update_packages("path/to/mypackage") does. Per the tutorial, I decided to install my package using devtools::install(). Is this because the process of installing my homebrew package requires setting up repository for updates?

Addressing the "cannot remove prior installation of package" error when updating multiple packages at once

This is a problem that comes up repeatedly, e.g.
Error in install.packages : cannot remove prior installation of package ‘DBI’
Warning in install.packages : cannot remove prior installation of package ‘data.table’
Unable to install package forecast in R
Install error of package plyr
Unable to install package zoo
I have come across this issue multiple times. Most annoying is when it occurs with a bunch of packages; e.g. I do something like
update.packages(ask = FALSE)
and get a number of these errors. The error is misleading though, because R tends to actually remove the old package version---but then doesn't install the new version. Once this happens, you can't fix it with update.packages; you have to reinstall it from scratch.
The most frustrating aspect of this problem is that it often occurs when installing dependencies, so e.g. I might successfully update dplyr, but in the process Rcpp is removed. Now I can't load dplyr because Rcpp is missing, so I need to reinstall Rcpp.
My current workaround (when the number of uninstalled packages is large) is to close all of my R sessions, open a new one with the base R GUI (i.e. not RStudio or RTVS) and do
lapply(dir(.libPaths()), install.packages)
which reinstalls my entire library. This is overkill.
Is there a better way to check which folders in .libPaths() actually contain packages, so that I only reinstall the missing packages?
Alternatively: Is there a better way to check for missing package depedencies?
One strategy is to do
setdiff(dir(.libPaths()), .packages(all = TRUE))
To get a list of directories in the library that don't seem to actually contain packages. Now I have a much smaller list of packages to reinstall.
I'm not sure if it's foolproof, but it's better than reinstalling my entire library.

Resources