Can't install sf on Workbench after latest server patch.

We recently updated our RStudio Workbench and Connect servers for our company. Since then we have been unable to install the sf package. I am getting the following log. Are we missing some kind of dependency? Thanks.

Installing 'sf' ...
Installing package into ‘/home/woodwards@dexcel.co.nz/R/x86_64-pc-linux-gnu-library/4.4’
(as ‘lib’ is unspecified)
trying URL 'https://cloud.r-project.org/src/contrib/sf_1.0-16.tar.gz'
Content type 'application/x-gzip' length 3493756 bytes (3.3 MB)
==================================================
downloaded 3.3 MB

* installing *source* package ‘sf’ ...
** package ‘sf’ successfully unpacked and MD5 sums checked
** using staged installation
configure: CC: gcc
configure: CXX: g++ -std=gnu++17
checking for gdal-config... /usr/bin/gdal-config
checking gdal-config usability... yes
configure: GDAL: 2.2.3
checking GDAL version >= 2.0.1... yes
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether the compiler supports GNU C... yes
checking whether gcc accepts -g... yes
checking for gcc option to enable C11 features... none needed
checking for stdio.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for strings.h... yes
checking for sys/stat.h... yes
checking for sys/types.h... yes
checking for unistd.h... yes
checking for gdal.h... yes
checking GDAL: linking with --libs only... yes
checking GDAL: /usr/share/gdal/2.2/pcs.csv readable... yes
checking GDAL: checking whether PROJ is available for linking:... yes
checking GDAL: checking whether PROJ is available for running:... yes
configure: GDAL: 2.2.3
configure: pkg-config proj exists, will use it
checking for proj_api.h... yes
configure: PROJ: 4.9.3
checking for pj_init_plus in -lproj... yes
checking PROJ: epsg found and readable... yes
checking for geos-config... /usr/bin/geos-config
checking geos-config usability... yes
configure: GEOS: 3.6.2
checking GEOS version >= 3.4.0... yes
checking for geos_c.h... yes
checking geos: linking with -L/usr/lib/x86_64-linux-gnu -lgeos_c... yes
configure: Package CPP flags:   -I/usr/include/gdal -I/usr/include
configure: Package LIBS: -lproj   -L/usr/lib -lgdal -L/usr/lib/x86_64-linux-gnu -lgeos_c
configure: creating ./config.status
config.status: creating src/Makevars
...
g++ -std=gnu++17 -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -Wl,-z,relro -o sf.so RcppExports.o bbox.o gdal.o gdal_geom.o gdal_read.o gdal_read_stream.o gdal_utils.o gdal_write.o geos.o hex.o mdim.o ops.o polygonize.o proj.o proj_info.o raster2sf.o sfc-sfg.o signed_area.o stars.o wkb.o zm_range.o -lproj -L/usr/lib -lgdal -L/usr/lib/x86_64-linux-gnu -lgeos_c -L/usr/lib/R/lib -lR
installing to /home/woodwards@dexcel.co.nz/R/x86_64-pc-linux-gnu-library/4.4/00LOCK-sf/00new/sf/libs
** R
** demo
** inst
** byte-compile and prepare package for lazy loading
in method for ‘dbWriteTable’ with signature ‘"PostgreSQLConnection","character","sf"’: no definition for class “PostgreSQLConnection”
in method for ‘dbDataType’ with signature ‘"PostgreSQLConnection","sf"’: no definition for class “PostgreSQLConnection”
in method for ‘coerce’ with signature ‘"Spatial","sf"’: no definition for class “Spatial”
in method for ‘coerce’ with signature ‘"Spatial","sfc"’: no definition for class “Spatial”
in method for ‘coerce’ with signature ‘"sf","Spatial"’: no definition for class “Spatial”
in method for ‘coerce’ with signature ‘"sfc","Spatial"’: no definition for class “Spatial”
in method for ‘coerce’ with signature ‘"XY","Spatial"’: no definition for class “Spatial”
in method for ‘coerce’ with signature ‘"crs","CRS"’: no definition for class “CRS”
in method for ‘coerce’ with signature ‘"sgbp","sparseMatrix"’: no definition for class “sparseMatrix”
** help
*** installing help indices
*** copying figures
** building package indices
** installing vignettes
** testing if installed package can be loaded from temporary location
Error: package or namespace load failed for ‘sf’ in dyn.load(file, DLLpath = DLLpath, ...):
 unable to load shared object '/home/woodwards@dexcel.co.nz/R/x86_64-pc-linux-gnu-library/4.4/00LOCK-sf/00new/sf/libs/sf.so':
  /home/woodwards@dexcel.co.nz/R/x86_64-pc-linux-gnu-library/4.4/00LOCK-sf/00new/sf/libs/sf.so: undefined symbol: _Z16CPL_set_data_dirN4Rcpp6VectorILi16ENS_15PreserveStorageEEEb
Error: loading failed
Execution halted
ERROR: loading failed
* removing ‘/home/woodwards@dexcel.co.nz/R/x86_64-pc-linux-gnu-library/4.4/sf’

The downloaded source packages are in
	‘/tmp/RtmpiwnQp5/downloaded_packages’


✔ Package 'sf' successfully installed.
Warning message:
In utils::install.packages("sf", repos = "https://cloud.r-project.org") :
  installation of package ‘sf’ had non-zero exit status

The sf package is known to be a troublemaker in unix based environments (where it is typically compiled from source) as it has external dependencies: GEOS, GDAL and PROJ libraries.

The error you describe has been known to occur in relation to the GDAL dependency, most often in case of multiple installations (such as one from distribution default and one manual).

Since the versions of the three external dependencies mentioned in your installation log are somewhat dated (read: among the lowest officially supported) you may want to purge them from your system and install newer ones manually (from source or via your preferred package manager). In the proces making sure that each library has only a single .so object present; something like sudo find / -name "libgdal*.so*" should be your friend here (libgdal usually lives in /usr/local/lib, but not always and there may be more than one in your PATH)

1 Like

Thank for your reply. Posit support said the problem is we are running an outdated version of Ubuntu, so waiting for that to be updated. If that doesn't work I'll check your advice.

This sounds reasonable; while you did not mention your ubuntu version it must be something rather old - given that focal fossa (20.04 / the oldest currently supported LTS) shipped with PROJ version 6.3.1, and you have 4.9.3 installed.

Upgrading your distribution will give you more current defaults of the big three libraries and thus - somewhat indirectly - solve the issue.

Should you wish to get more serious with GIS and spatial analysis you are likely to end up with installing the big three manually anyhow to get more control; but upgrading your server version OS feels as a good idea for other reasons as well (my hunch is that you are running Bionic Beaver / the 18.04 LTS which is no longer a good practice).

1 Like