3

I am using Rstudio server on a remote server and I have some packages already installed.

When I try to load libraries like raster or terra using Rstudio server, I get error:

> library(terra)

Error: package or namespace load failed for ‘terra’ in dyn.load(file, DLLpath = DLLpath, ...):
 unable to load shared object '/home/pearless/R/x86_64-pc-linux-gnu-library/4.1/terra/libs/terra.so':
  libproj.so.15: cannot open shared object file: No such file or directory

> library(raster)

Error: package or namespace load failed for ‘raster’ in dyn.load(file, DLLpath = DLLpath, ...):
 unable to load shared object '/home/pearless/R/x86_64-pc-linux-gnu-library/4.1/terra/libs/terra.so':
  libproj.so.15: cannot open shared object file: No such file or directory

Please, note that loading other packages using Rstudio server such as tidyverse works just fine:

> library(tidyverse)

── Attaching packages ──────────────────────────────────────────────────────────────────────────────────────── tidyverse 1.3.1 ──
✓ ggplot2 3.3.5     ✓ purrr   0.3.4
✓ tibble  3.1.6     ✓ forcats 0.5.1
✓ readr   2.0.2     
── Conflicts ─────────────────────────────────────────────────────────────────────────────────────────── tidyverse_conflicts() ──
x dplyr::filter() masks stats::filter()
x dplyr::lag()    masks stats::lag()

When I use R console in the server without using Rstudio server, the raster and terra packages can be loaded without any problem:

$ R

R version 4.1.1 (2021-08-10) -- "Kick Things"
Copyright (C) 2021 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(terra)
terra version 1.4.11

> library(raster)
Loading required package: sp

How can I solve this problem, so that I can also load these packages in Rstudio server?

UPDATE based on @user2554330's comment:

  1. .libPaths() gives exactly the same result in both.

  2. Sys.getenv("PATH") and Sys.getenv("LD_LIBRARY_PATH") give different results in R and Rstudio server consoles - Rstudio server does not seem to be seeing most of the path variables. I ran pth = Sys.getenv("PATH") and ld_pth = Sys.getenv("LD_LIBRARY_PATH") in R in the server, and copied the results and pasted them into Sys.setenv(PATH = "result_of_pth") and Sys.setenv(PATH = "result_of_ld_pth") in the Rstudio server respectively. After doing this, I still get the same error when I load the libraries raster and terra.

  3. Yes, both are running with the same username.

Phil
  • 7,287
  • 3
  • 36
  • 66
bird
  • 2,938
  • 1
  • 6
  • 27
  • 1
    There are lots of possibilities. Are both versions using the same libraries? (Run `.libPaths()` in both to check.) Do both see the same environment variables, including `PATH` and `LD_LIBRARY_PATH`? Are both running with the same username? – user2554330 Nov 30 '21 at 10:48
  • @user2554330 please see the update and kindly let me know what you think :) – bird Nov 30 '21 at 11:54
  • 1
    Have you tried reinstalling those packages as root? – runr Nov 30 '21 at 12:02
  • @runr would you please clarify what you mean by installing as "root"? – bird Nov 30 '21 at 12:05
  • Through, e.g., ``sudo R``, from there running ``install.package(..)`` again for those packages that cause issues – runr Nov 30 '21 at 12:08
  • @runr it seems like I am not allowed to run `sudo R` as it is a remote server and I have no permission to run this command. Why do you think it would help? :) – bird Nov 30 '21 at 12:12
  • Sorry, I can't think of anything. You might find some useful information if you run `maketools::package_sysdeps("terra")` or `maketools::package_sysdeps("raster")`. – user2554330 Nov 30 '21 at 12:13

2 Answers2

4

Per robert-hijmans reply, I solved this by adding the following:

apt-get -y update && apt-get install -y \
    libudunits2-dev \
    libgdal-dev \
    libgeos-dev \
    libproj-dev \
    libmysqlclient-dev 
danlooo
  • 10,067
  • 2
  • 8
  • 22
Jake Wang
  • 57
  • 1
  • 6
2

The problem appears to be that terra does not work, and because raster depends on it, that package cannot load either.

From a Google search on the error message libproj.so.15: cannot open shared object file: No such file or directory I see this and this discussion, and perhaps more relevant pages.

These discuss the sf package but that package uses the same system dependencies as terra, so this should apply to terra as well.

Robert Hijmans
  • 40,301
  • 4
  • 55
  • 63