How to configure R on a Linux system for spatial work

Hi, I could use help with configuring my R installation for spatial work. Because I was having difficulties to install spatial packages I used this set of instructions to help: https://rtask.thinkr.fr/installation-of-r-4-0-on-ubuntu-20-04-lts-and-tips-for-spatial-packages/

But I am still getting errors related to shared object files. I'd appreciate any insight into what may be the problem. (If you think it is better to post to the R stack exchange instead I can do that)

My system:

 OS: Ubuntu 20.04 focal
 Kernel: x86_64 Linux 5.4.0-66-generic
 Uptime: 33m
 Packages: 3542
 Shell: bash 5.0.17
 Resolution: 2560x1080
 DE: KDE 5.68.0 / Plasma 5.18.5
 WM: KWin
 GTK Theme: Breeze [GTK2/3]
 Icon Theme: breeze-dark
 Disk: 1.2T / 1.9T (66%)
 CPU: Intel Core i5-4460 @ 4x 3.4GHz [35.0°C]
 GPU: GeForce GTX 1050 Ti
 RAM: 3411MiB / 15954MiB

My R version:

R version 4.0.4 (2021-02-15) -- "Lost Library Book"
Copyright (C) 2021 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

My attempted command and resulting error:

> install.packages(c("tigris", "tidycensus"))
Installing packages into ‘/home/user/R/x86_64-pc-linux-gnu-library/4.0’
(as ‘lib’ is unspecified)
trying URL 'https://cloud.r-project.org/src/contrib/tigris_1.0.tar.gz'
Content type 'application/x-gzip' length 262369 bytes (256 KB)
==================================================
downloaded 256 KB

trying URL 'https://cloud.r-project.org/src/contrib/tidycensus_0.11.4.tar.gz'
Content type 'application/x-gzip' length 1753003 bytes (1.7 MB)
==================================================
downloaded 1.7 MB

* installing *source* package ‘tigris’ ...
** package ‘tigris’ successfully unpacked and MD5 sums checked
** using staged installation
** R
** data
*** moving datasets to lazyload DB
** byte-compile and prepare package for lazy loading
Error in dyn.load(file, DLLpath = DLLpath, ...) : 
  unable to load shared object '/home/user/R/x86_64-pc-linux-gnu-library/4.0/rgdal/libs/rgdal.so':
  libgdal.so.26: cannot open shared object file: No such file or directory
Calls: <Anonymous> ... namespaceImport -> loadNamespace -> library.dynam -> dyn.load
Execution halted
ERROR: lazy loading failed for package ‘tigris’
* removing ‘/home/user/R/x86_64-pc-linux-gnu-library/4.0/tigris’
Warning in install.packages :
  installation of package ‘tigris’ had non-zero exit status
ERROR: dependency ‘tigris’ is not available for package ‘tidycensus’
* removing ‘/home/user/R/x86_64-pc-linux-gnu-library/4.0/tidycensus’
Warning in install.packages :
  installation of package ‘tidycensus’ had non-zero exit status

The downloaded source packages are in
	‘/tmp/Rtmp1UzoRP/downloaded_packages’
Warning in install.packages :
  converting NULL pointer to R NULL
1 Like

You are missing a system library, try installing it from a system terminal.

sudo apt install libgdal-dev

Good try but,

$ sudo apt install libgdal-dev
Reading package lists... Done
Building dependency tree       
Reading state information... Done
libgdal-dev is already the newest version (3.2.1+dfsg-1~focal0).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

The problem is on my system. On my test system with a new and clean installation of Kubuntu 20.04 LTS, I was able to install both R (4.0.4) , RStudio (version 1.4.1106) and the desired packages c("tigris", "tidycensus")) with no errors.

I found the solution on this page: https://stackoverflow.com/questions/61875754/r-load-error-libproj-so-13-cannot-open-shared-object-file-no-such-file-or-di

Start an R session with root:

sudo R

Then install the packages. In my case:

install.packages("tigris")

After the installation completes, use q() to exit.

This means, that my issue had to do with how R interacts with the user accounts and permissions on my PC.

3 Likes

Thanks for marking your solution. Makes the discussion more useful for others. One annoyance with R packages is the distinction of system packages (installed with sudo) and user packages installed into the local directory. This is well and fine for server based systems, the paradigm from which UNIX and its descendants are based) and the single-user systems that the vast majority of us are using.

Then there are $PATH issues to contend with and disturbances of The Force arising from competing installations of other programs, such as Python when using {retriculate}. And the wonderful Python package manager Anaconda has been a disappointment as an R package manager, as well as multiplying problems identifying the correct Python $PATH.

And don't get me started on containers and virtual environments!

I bet it was Anaconda that fuzzied up my $PATH. I had issues with my ruby gems and jekyll as well that I tracked down to the $PATH. Do you know if conda or miniconda is a better alternative? Or is there a recommended way to install anaconda on a linux system so that it doesn't disrupt the ecosystem?

I think it depends on how much importance is attached to the details of package management. My install doesn't have a lot of Python packages to manage, so I've addressed the issue with aliases such as alias py='/usr/bin/python3.9' to do most of my work in Python and left the 3.8 OS and 3.8 Anaconda in place for when needed. Correspondingly for pip and ipython.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.