R version 3.4.0 rgdal will not load - r

I recently installed the latest version of R (3.4.0) and installed all of my packages, but for some reason rgdal will not load and I'm getting this message:
library(rgdal)
Error: package or namespace load failed for ‘rgdal’ in dyn.load(file, DLLpath = DLLpath, ...):
unable to load shared object '/Library/Frameworks/R.framework/Versions/3.4/Resources/library/rgdal/libs/rgdal.so':
dlopen(/Library/Frameworks/R.framework/Versions/3.4/Resources/library/rgdal/libs/rgdal.so, 6): Library not loaded: /Builds/unix/recipes/build/gdal-2.1.3-obj/libgdal.dylib
Referenced from: /Library/Frameworks/R.framework/Versions/3.4/Resources/library/rgdal/libs/rgdal.so
Reason: image not found
I went to the rgdal/libs directory and the rgdal.so file exists, but for some reason doesn't want to load. Anyone else have this issue or a similar one?

Try installing RStudio and re-download it from there or type install.packages("rgdal"). If none of these work try installing another package and see if you can run it, because it is either the directory, the package or the version of the package is not compatible with the version of the language.

Do you have GDAL OS X frameworks installed? If not, go to William Kyngesburye's site, download and install frameworks in the following order:
GDAL Complete
GSL Framework
FreeType
cairo
After completing this installation, go for steps 2 and 3 of this answer, and then, install rgdal from R.app using these specifications in the install.packages command.
It solved the problem for me, hope it helps you!

Seems to be related to my issue posted same day, Unable to load pgirmess library ("image not found") - R 3.4 in Mac OS .
I installed the previous version of R from CRAN (3.3.3), and it works fine. You can have both versions installed at the same time. Maybe not a long term solution but at least a temporary fix so your work can continue.

Related

plot KML library load fail, unable to load shared object

Not sure if relevant, but I'm getting this error after a recent update to Mac OS Monterey Version 12.5.1.
After trying library(plotKML) I get the following:
Error: package or namespace load failed for ‘plotKML’ in dyn.load(file, DLLpath = DLLpath, ...):
unable to load shared object '/Users/kchalkowski/Library/R/x86_64/4.1/library/lwgeom/libs/lwgeom.so':
dlopen(/Users/kchalkowski/Library/R/x86_64/4.1/library/lwgeom/libs/lwgeom.so, 0x0006): Library not loaded: '/usr/local/opt/proj/lib/libproj.22.dylib'
I checked the directory /usr/local/opt/proj/lib and sure enough, libproj.22.dylib is not there. Rather, another version is there in it's place: libproj.25.dylib.
Is there a way to get that older version of libproj? or a way to link plotKML to the correct dylib? I had a similar issue with sf, but was able to fix it with a brew reinstall of pkg-config gdal proj geos in the terminal, and uninstalling and reinstalling sf. I've tried uninstalling and reinstalling plotKML but to no avail.
Did a search for the name of the dynamic library and I think I actually just fixed it following advice here: https://github.com/flow-project/flow/issues/896
I used the following in the terminal but instead of 19/5, I replaced the versions of the libraries in the code here with the one I have (25) and the one plotKML wants (22), and it seems to be working now?:
ln -s /usr/local/opt/proj/lib/libproj.19.dylib /usr/local/opt/proj/lib/libproj.15.dylib

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.

R: install uroot package in ubuntu

I am trying to install the forecast package which depends on uroot, which apparently have been written to require a GPU?
install.packages("uroot") yields the following error. Has anyone found this issue and may suggest a work around? I am using ubuntu 16.04.
I have the file in question located here: /usr/local/cuda-8.0/ and I added to my path export PATH=/usr/local/cuda-8.0/:$PATH
Error in dyn.load(file, DLLpath = DLLpath, ...) :
unable to load shared object '/home/rstudio2/R/x86_64-pc-linux-gnu-library/3.2/uroot/libs/uroot.so':
libcudart.so.8.0: cannot open shared object file: No such file or directory
Error: loading failed
Execution halted
ERROR: loading failed
* removing ‘/home/rstudio2/R/x86_64-pc-linux-gnu-library/3.2/uroot’
Warning in install.packages :
installation of package ‘uroot’ had non-zero exit status
Just in case this is useful for someone, I stumbled with the same problem trying to install "imputeTS" with R version 3.5.1 on Fedora 27 with CUDA 10.0 correctly installed an setted in PATH.
for me it just happened that I was running install.package("imputeTS") (which depends on forecast) in a R console as root, installing the packages to the user home solved the problem. It's seems that the libraries are searched in different places according to the user running the script, it's important to note that.
I just migrated to Linux. On an Ubuntu 18.04 setup, using install.packages with dependencies set to TRUE succeeded with no complaints. (No GPU on mu box.)
install.packages("forecast", dep=TRUE)
# there are quite a few dependencies and you happened to be missing one
packageDescription()
#-----------includes this line----------
Imports: colorspace, fracdiff, ggplot2 (>= 2.2.1), graphics, lmtest,
magrittr, nnet, parallel, Rcpp (>= 0.11.0), stats,
timeDate, tseries, urca, uroot, zoo
You can try to modify file "/etc/rstudio/rserver.conf", add "LD_LIBRARY_PATH" env, like:
rsession-ld-library-path=/usr/local/cuda/lib64
Actually, When you open session of "RStudio Server" from browser, the session does't get env from the ".bashrc".

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.

RQDA - cannot load RGtk2.so

I've been trying to solve this one for ages.
I want to use RQDA on my Mac. I have installed it (install.packages("RQDA")fine. But when I go to run it it asks if I need GTK+. I keep saying yes, but it fails.
library(RQDA)
Loading required package: RSQLite
Loading required package: gWidgetsRGtk2
Loading required package: RGtk2
Error in dyn.load(file, DLLpath = DLLpath, ...) :
unable to load shared object '/Library/Frameworks/R.framework/Versions/3.3/Resources/library/RGtk2/libs/RGtk2.so':
dlopen(/Library/Frameworks/R.framework/Versions/3.3/Resources/library/RGtk2/libs/RGtk2.so, 6):
Library not loaded: /usr/X11/lib/libXinerama.1.dylib
Referenced from: Library/Frameworks/GTK+.framework/Versions/2.24.X11/Resources/lib/libgtk-x11-2.0.0.dylib
Reason: image not found
Need GTK+ ? (Restart R after installing)
1: Install GTK+
2: Do not install GTK+
I have checked my library path and found that the package is there but in the 3.3 version. It is sitting there "RGtk2.so".
libPaths()
[1] "/Library/Frameworks/R.framework/Versions/3.3/Resources/library"
I have googled this to death. Any ideas would be much appreciated!
After you have installed the RQDA package, and you call the library RQDA, be careful because a popup window raises asking for install RGtk2+ components. But that window can be hidden by your open aplications over the desktop. Look for the popup window and answer yes for install. Once is installed, won't be more problems.
Install GTK from http://r.research.att.com/libs/GTK_2.24.17-X11.pkg. Make sure you have the latest XQuartz from https://www.xquartz.org/

Resources