unable to load PROJ while installing "sf" package

I am getting the following error while trying to install "sf" package. I have PROJ installed but still getting this error

#
> install.packages("sf")
> Installing package into ‘/home/pa21596/R/x86_64-redhat-linux-gnu-library/3.6’
> (as ‘lib’ is unspecified)
> trying URL 'https://cran.rstudio.com/src/contrib/sf_0.9-3.tar.gz'
> Content type 'application/x-gzip' length 8483731 bytes (8.1 MB)
> ==================================================
> downloaded 8.1 MB
> 
> * installing *source* package ‘sf’ ...
> ** package ‘sf’ successfully unpacked and MD5 sums checked
> ** using staged installation
> configure: CC: gcc -m64 -std=gnu99
> configure: CXX: g++ -m64 -std=gnu++11
> checking for gdal-config... /usr/bin/gdal-config
> checking gdal-config usability... yes
> configure: GDAL: 2.2.1
> checking GDAL version >= 2.0.1... yes
> checking for gcc... gcc -m64 -std=gnu99
> 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 we are using the GNU C compiler... yes
> checking whether gcc -m64 -std=gnu99 accepts -g... yes
> checking for gcc -m64 -std=gnu99 option to accept ISO C89... none needed
> checking how to run the C preprocessor... gcc -m64 -std=gnu99 -E
> checking for grep that handles long lines and -e... /usr/bin/grep
> checking for egrep... /usr/bin/grep -E
> checking for ANSI C header files... yes
> checking for sys/types.h... yes
> checking for sys/stat.h... yes
> checking for stdlib.h... yes
> checking for string.h... yes
> checking for memory.h... yes
> checking for strings.h... yes
> checking for inttypes.h... yes
> checking for stdint.h... yes
> checking for unistd.h... yes
> checking gdal.h usability... yes
> checking gdal.h presence... yes
> checking for gdal.h... yes
> checking GDAL: linking with --libs only... yes
> checking GDAL: /usr/share/gdal/pcs.csv readable... yes
> checking GDAL: checking whether PROJ is available for linking:... yes
> checking GDAL: checking whether PROJ is available fur running:... ERROR 6: Unable to load PROJ.4 library (libproj.so), creation of OGRCoordinateTransformation failed.
> no
> configure: error: OGRCoordinateTransformation() does not return a coord.trans: PROJ not available?
> ERROR: configuration failed for package ‘sf’
> * removing ‘/home/pa21596/R/x86_64-redhat-linux-gnu-library/3.6/sf’
> Warning in install.packages :
>   installation of package ‘sf’ had non-zero exit status
> 
> The downloaded source packages are in
> 	‘/tmp/RtmpGNk5B4/downloaded_packages’
#

Any forward in this issue will be really helpful.

The first thing I would try is updating symbolic links: sudo ldconfig; especially if the PROJ install was a recent thing.

The second would be locating your PROJ installation manually and pointing the {sf} package to the directory via --with-proj-lib configure argument:

install.packages("sf", configure.args = "--with-proj-lib=/here/comes/the/path")
1 Like

In addition to @jlacko suggestions: How did you install PROJ. What is the output of sudo ldconfig -p | grep libproj?

1 Like

@Pranav_Arora - We're also on Red Hat (v7) and we were able to get around this by installing the rproj-devel RPM (then we also had to install geos-devel as well as proj-nad and proj-epsg, all from EPEL).

1 Like

When I publish a shiny app in RStudio Connect, I get the error message:
no
configure: error: OGRCoordinateTransformation() does not return a coord.trans: PROJ not available?
ERROR: configuration failed for package ‘sf’
*** removing ‘/opt/rstudio-connect/mnt/app/packrat/lib/x86_64-pc-linux-gnu/4.4.1/sf’**
Unable to fully restore the R packages associated with this deployment.

I am using R version 4.4.1. And gdal-config --version 3.4.3, and proj --version Rel. 8.2.0.

The sudo ldconfig -p | grep libproj, gives:
libproj.so.22 (libc6,x86-64) => /lib/x86_64-linux-gnu/libproj.so.22
libproj.so.15 (libc6,x86-64) => /lib/x86_64-linux-gnu/libproj.so.15
libproj.so (libc6,x86-64) => /lib/x86_64-linux-gnu/libproj.so

Any suggestion? It looks like rgdal package is not available and this may be because of that. Any help?

The issue is fixed. It was related to " Multiple GDAL, GEOS and/or PROJ versions on my system".