Error: node stack overflow and GDAL Error when making ggplot map

Viewed 191

Following this tutorial, I am trying to plot a map with the ggplot2 and sf packages. Just as in the tutorial, my code is:

library(ggplot2)
library(sf)
library(rnaturalearth)
library(rnaturalearthdata)
library(rgeos)

world <- ne_countries(scale = "medium", returnclass = "sf")
class(world)
ggplot(data = world) + geom_sf()

However, when I run this code on the Linux machine I must work on, I get the following error and warning (repeated many times):

Error: node stack overflow
In addition: There were 50 or more warnings (use warnings() to see the first 50)
> warnings()
Warning messages:
1: In CPL_crs_from_input(x) :
GDAL Error 1: PROJ: proj_create_from_database: Open of /home/<redacted>/miniconda3/envs/r_env2/share/proj failed

However, on my home computer, I get the expected output: expected map output

Here is some possibly relevant information:

Work computer:

sessionInfo()
R version 3.6.3 (2020-02-29)
Platform: x86_64-conda_cos6-linux-gnu (64-bit)
Running under: Red Hat Enterprise Linux

Matrix products: default
BLAS/LAPACK: /home/<redacted>/miniconda3/envs/r_env2/lib/libopenblasp-r0.3.6.so

locale:
[1] C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] rgeos_0.5-3             sp_1.4-2                rnaturalearthdata_0.1.0
[4] rnaturalearth_0.1.0     sf_0.9-4                ggplot2_3.1.1

> system('free -m')
              total        used        free      shared  buff/cache   available
Mem:         257665       42503       73665         298      141496      177005
Swap:         80595        4577       76018

Home computer:

R version 4.0.2 (2020-06-22)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

Matrix products: default

Random number generation:
 RNG:     Mersenne-Twister 
 Normal:  Inversion 
 Sample:  Rounding 
 
locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] rgeos_0.5-3             sp_1.4-2                rnaturalearthdata_0.1.0
[4] rnaturalearth_0.1.0     sf_0.9-4                ggplot2_3.3.2

> memory.limit()
[1] 1.759219e+13

Unfortunately, I cannot do this work on my home computer. The datasets I need to interact with the map are simply too large.

Thank you very much!

1 Answers

I had the same error message resulting from multiple GDAL installations being in conflict with each other (along the lines of this issue). I had installed an additional version of gdal from the commandline and somehow broke the link sf to PROJ. I was only able to solve it reinstalling ubuntu. Now I'm more thoughtful when installing packages and keep a journal of what I installed.

The following installation allowed me to use the newest version of gdal (and related libraries) from the terminal as well as through sf

# install the newest version of sf dependencies 
sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable
sudo apt-get update
sudo apt-get install libudunits2-dev libgdal-dev libgeos-dev libproj-dev 

# install gdal to use gdal and ogr2ogr from the commandline
sudo apgt-get install gdal-bin
Related