2

I have successfully installed the rgdal package along with the dependencies GDAL and Proj4. After installation I succesfully loaded the package in R with the library function. However after my most recent login when i type in the command library(rgdal) I get an error message:

Error: package or namespace load failed for 'rgdal' in dyn.load(file, 
DLLpath = DLLpath, ...):
unable to load shared object '/home/nikhail1/R/x86_64-pc-linux-gnu-
library/3.4/rgdal/libs/rgdal.so':
libgdal.so.20: cannot open shared object file: No such file or directory

I understand this means there is no link to the libgdal file but I am not sure how to fix it. libgdal.so.20 is in the system under /home/nikhail1/bin/gdal/lib/. The rgdal.so file is under the rgdal folder in the R library in my /home/nikhail1/ system. I do not have the authority to perform an ldconfig function on shared libraries (I am a novice). Does anyone have a function that could help me make the system recognize the pathway to libgdal.so.20. I am working on a Linux CentOs 6.9 system. I cannot perform any sudo apt-get, yum or brew functions.

Many thanks, Nikhail

2 Answers 2

6

You can set LD_LIBRARY_PATH to include /home/nikhail1/bin/gdal/lib, i.e. in bash

export LD_LIBRARY_PATH="/home/nikhail1/bin/gdal/lib:$LD_LIBRARY_PATH"
ldd /home/nikhail1/R/x86_64-pc-linux-gnu-library/3.4/rgdal/libs/rgdal.so

should report libgdal.so.20 as been found. How to make this persistent depends on your desktop environment.

4
  • Thank you. This seems to have fixed the first error. Now getting a similar error message saying Error: package or namespace load failed for 'rgdal' in dyn.load(file, DLLpath = DLLpath, ...): unable to load shared object '/home/nikhail1/R/x86_64-pc-linux-gnu-library/3.4/rgdal/libs/rgdal.so': libproj.so.9: cannot open shared object file: No such file or directory. Feb 16, 2018 at 9:41
  • The libproj.so.9 file can be found in home/nikhail1/bin/proj-4.9.2/lib. Do i use the same command as you have suggested for libgdal.so? Feb 16, 2018 at 9:42
  • You are welcome. Please accept/up-vote the answer if it was helpful. Feb 16, 2018 at 10:32
  • I did, but because my reputation is so low the upvote is recorded but not publicly displayed. Sorry, but thank you very much nonetheless Feb 16, 2018 at 12:07
1

I've suffered quite a lot with gdal, rgdal and the proper setting of these in order to run rgdal functions in R. My bulletproof routine at the moment is the following:

UNINSTALL GDAL

sudo apt-get remove gdal-bin 

Uninstall gdal-bin including dependent package

If you would like to remove gdal-bin and it's dependent packages which are no longer needed from Ubuntu,

sudo apt-get remove --auto-remove gdal-bin 

Use Purging gdal-bin If you use with purge options to gdal-bin package all the configuration and dependent packages will be removed.

sudo apt-get purge gdal-bin 

If you use purge options along with auto remove, will be removed everything regarding the package, It's really useful when you want to reinstall again.

sudo apt-get purge --auto-remove gdal-bin 

Just to be sure if you've tried and failed many times to install it and it doesn't work, run all of these in sequential order.

INSTALL GDAL

sudo apt-get update
sudo apt-get install gdal-bin proj-bin libgdal-dev libproj-dev -y

INSTALL RGDAL

IN R:

install.packages('rgeos', type='source')

install.packages('rgdal', type='source')

Now everything should load and run smooth.

1
  • Thank you Momchill. I have since moved on from cluster computing in R (for now) however, I will keep this post up so helpful answers such as yours will benefit others with similar issues, which seem to be relatively persistent among even regular users of gdal. Oct 15, 2021 at 7:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.