R packages not loading via library() - r

I have been experiencing the problem of not being able to load package libraries in R. The packages install fine via instal.packages(), but I get the error
Error: package or namespace load failed for ‘adegenet’ in library.dynam(lib, package, package.lib):
shared object ‘httpuv.so’ not found
Error: package ‘adegenet’ could not be loaded
When I attempt to load the package 'adegenet' (and any other packages).
I recall this behaviour started to occur when I used remove.packages() to remove shiny in order to install the development version on GitHub (shiny-Incubator).
I am unsure as to what is going on. Any ideas on how to restore everything? I updated to the most recent R version, but this did not fix things.

It seems that during your uninstallation procedure you managed to remove a component of httpuv and/or Rcpp. This should get things working again:
install.packages(c("Rcpp", "httpuv"))

Related

clusterProfiler cannot load package

I am trying to load clusterProfiler, but regardless of how I install the package or whether I un-install or re-install, I continue to get the below error when I attempt to load it. I have also recently installed and loaded patchwork. Appreciate any tips.
Error: package or namespace load failed for ‘clusterProfiler’:
object ‘patchworkGrob’ is not exported by 'namespace:patchwork'
I had the same issue, and I solved it by loading the library(patchwork) before loading clusterProfiler.
Hope it helps~

A package that needs compilation cannot be installed with a different name

I have a github clone of the glue R package for reasons. The name of this package is changed into glue.1.3.1 in this repository from its DESCRIPTION file for similar reasons. As a control group, I have an identical repository but this one's name is not changed in any way
If I do
devtools::install_github('oganm/glue.1.3.1')
the installation will fail
Error: package or namespace load failed for ‘glue.1.3.1’ in library.dynam(lib, package, package.lib):
shared object ‘glue.so’ not found
Error: loading failed
Execution halted
If I do
devtools::install_github('oganm/glue)
the installation will be successful.
If I do the same thing to most other packages, there are no problems but it seems like the source code of pacakges that need compilation, the change in the package name causes problems. For instance, you can repeat the issue with dplyr here
The question is, what causes this issue? What do I need to do so that I can reliably change names of packages that require compilation?

Issue with loading Tidyverse in RStudio

How to do i resolve the following code error?
library(tidyverse)
Error: package or namespace load failed for ‘tidyverse’:
.onLoad failed in loadNamespace() for 'tidyselect', details:
call: is_string(x)
error: object 'rlang_is_string' not found
In addition: Warning message:
package ‘tidyverse’ was built under R version 3.5.3
For persistent errors of type, first, ensure you are working with the latest version of R. The installr package is a very convenient way to do this.
Then, start new R session (ideally, not in RStudio).
Uninstall tidyverse, tidyselect, and rlang
# if you are using multiple libraries, you may need to specify libpath,
# using the following: lib="~/R/win-library/3.6"
# you can check using the .libPaths() command
remove.packages("rlang")
remove.packages("tidyselect")
remove.packages("tidyverse")
and, reinstall them one by one with dependencies = TRUE
install.packages("rlang", dependencies = TRUE)
install.packages("tidyselect", dependencies = TRUE)
install.packages("tidyverse", dependencies = TRUE)
That should do it.
I also encounter a similar problem like you, which I'm unable to load the tidyverse too.
Hope this discuss from the tidyverse github issues maybe relevant to you.
https://github.com/tidyverse/googledrive/issues/275
Here's one of our typical explanations of this. Note that this is not specific to googledrive or rlang. It's an R + Windows gotcha. I suspect for you is rlang (at least).
Please note that on Windows, it is very important to quit or restart
all R processes before upgrading , because if any R process has
loaded, it will keep the .dll file open and the installer will not be
able to overwrite .dll. The error message when this happens is very
easy to overlook, and the new version will be partially installed: the
package description and R code will be updated but the compiled code
(in .dll) will not.

Fail to load libraries after upgrading R to 3.6.0 on Mac

I needed to install the R package quadprog, which only works for R with version 3.6.0. So I installed R (3.6.0 version), and open it with RStudio. But now I failed to load any libraries, even after I installed the packages successfully using install.packages("package_name"). Specifically, the libraries I need to load are caret, forecast and ggplot2. I tried re-installing R but it still does not work. The error message I get is
Error: package or namespace load failed for ‘forecast’ in
dyn.load(file, DLLpath = DLLpath, ...): unable to load shared object
'/Library/Frameworks/R.framework/Versions/3.6/Resources/library/Rcpp/libs/Rcpp.so':
dlopen(/Library/Frameworks/R.framework/Versions/3.6/Resources/library/Rcpp/libs/Rcpp.so,
6): Symbol not found: ___cxa_uncaught_exceptions Referenced from:
/Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libc++.1.dylib
Expected in: /usr/lib/libc++abi.dylib in
/Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libc++.1.dylib
After installing Rcpp package successfully with install.packages("Rcpp") , I still got the message above when I tried library(Rcpp). So I am completely stumbled here...(before upgrades, everything works fine except I cannot install quadprog, so cannot install forecast package as well). Can anyone please help me fix this issue?
Please see below the images showing that the packages are stored in the same directory path of the R.
I read that you need to recompile your old packages after upgrading to newer version of R. Run the following line in your R terminal
update.packages(ask=FALSE,
checkBuilt=TRUE,
repos="https://cloud.r-project.org")
Then
install.packages(c("Rcpp", "caret", "forecast", "ggplot2", "quadprog"),
dependencies=TRUE,
repos="https://cloud.r-project.org")
Had similar issue, restart R session and install Rcpp from source
install.packages("Rcpp", type="source")
then load the library
library(Rcpp)
if still getting the error, restart R session and try loading library again.
I ended up by getting and then google searching the exact error code :). I fixed it by installing the latest version of R from CRAN along with the latest version of Rstudio. What I think happened was that when I updated some packages R and Rstudio were out of sync.

NLoptr failed to install on Mac: unable to load shared object

I'm trying to install the package nloptr on Mac OS High Sierra in order to use many nice packages like lme4, and I'm using RStudio inside Anaconda, with R 3.4.2. I have also installed NLopt (downloaded from the NLopt website, not the development version. I have also installed Xcode command line tool. But I still can't install nloptr, and get this
Error: package or namespace load failed for ‘nloptr’ in dyn.load(file, DLLpath = DLLpath, ...):
unable to load shared object '/Users/lambda/anaconda3/lib/R/library/nloptr/libs/nloptr.so':
dlopen(/Users/lambda/anaconda3/lib/R/library/nloptr/libs/nloptr.so, 6): Symbol not found: _nlopt_add_equality_mconstraint
Referenced from: /Users/lambda/anaconda3/lib/R/library/nloptr/libs/nloptr.so
Expected in: flat namespace
in /Users/lambda/anaconda3/lib/R/library/nloptr/libs/nloptr.so
I already searched online for what to do, and did add the path where NLopt was installed to LD_LIBRARY_PATH in the /etc/ldpaths file, but I still get the same error. Yes, I have the same problem as in Trouble installing nloptr package on R 3.3.0, but I didn't find a solution that works there since the person who asked that question resolved it himself and I don't know what he meant when he said "installed as a root". Can anyone help?
Also, I got something like this when installing NLopt with CMake, and this happened to many different functions:
In file included from f77api.c:103:
./f77funcs.h:57:14: warning: 'nlopt_minimize_constrained' is deprecated
[-Wdeprecated-declarations]
*info = nlopt_minimize_constrained((nlopt_algorithm) *algorithm,
^
./nlopt.h:348:35: note: 'nlopt_minimize_constrained' has been explicitly marked
deprecated here
int maxeval, double maxtime) NLOPT_DEPRECATED;
^
./nlopt.h:320:43: note: expanded from macro 'NLOPT_DEPRECATED'
# define NLOPT_DEPRECATED __attribute__((deprecated))
^
Would this be why the library isn't loaded?
BTW, I have installed Rcpp and updated it. Rcpp works on my computer.
Update: I changed the default C and C++ compiler to clang4 downloaded from R project. I tried the installation again, and got a different error:
Error: package or namespace load failed for ‘nloptr’ in dyn.load(file, DLLpath = DLLpath, ...):
unable to load shared object '/Users/lambda/anaconda3/lib/R/library/nloptr/libs/nloptr.so':
dlopen(/Users/lambda/anaconda3/lib/R/library/nloptr/libs/nloptr.so, 6): Library not loaded: #rpath/libnlopt.0.dylib
Referenced from: /Users/lambda/anaconda3/lib/R/library/nloptr/libs/nloptr.so
Reason: image not found
Error: loading failed
I have tried to tell R where the library is by Sys.geteng(DYLD_LIBRARY_PATH = "/usr/local/lib"), but it didn't work. It actually appears that R does know where the shared library is, according to the messages I got from installation, but it just can't load it. Please help!
Never mind, I reinstalled Anaconda, and installed the standalone R and RStudio (not within Anaconda), and those packages all installed successfully. Maybe it's a bad idea to use the RStudio inside Anaconda.
Edit: For those who run into similar scenarios: I switched to Microsoft R Open (MRO), since I'm dealing a lot with linear algebra recently. Then when I tried to install nloptr in MRO, I got a similar error message that shared library failed to load because image not found. I reinstalled the CRAN R 3.4.3 and nloptr installed totally fine there. So I found where nloptr was installed in CRAN R 3.4.3 by .libPaths(), copied the nloptr folder to where MRO stores packages, and used the utility RSwitch to change the default version of R to MRO. Then I loaded nloptr in MRO, installed packages that depend on it, and used those packages; they worked fine. I don't know what's wrong with MRO that caused the error, but at least this worked.

Resources