5

I just updated R (from 4.0.2 to 4.0.3) and all my R packages (previously updated about a month ago), and got an error in a previously working workflow on raster objects. It seems that it comes from the CRS that can't be found anymore:

If I run

sp::CRS("+init=epsg:4326")
sp::CRS(SRS_string='EPSG:4326')

I get respectively those errors

Error in sp::CRS("+init=epsg:4326") : NA
Error in sp::CRS(SRS_string = "EPSG:4326") : NA

But it works perfectly fine with sf function

sf::st_crs(4326)
Coordinate Reference System:
  User input: EPSG:4326 
  wkt:
GEOGCRS["WGS 84",
    DATUM["World Geodetic System 1984",
        ELLIPSOID["WGS 84",6378137,298.257223563,
            LENGTHUNIT["metre",1]]],
    PRIMEM["Greenwich",0,
        ANGLEUNIT["degree",0.0174532925199433]],
    CS[ellipsoidal,2],
        AXIS["geodetic latitude (Lat)",north,
            ORDER[1],
            ANGLEUNIT["degree",0.0174532925199433]],
        AXIS["geodetic longitude (Lon)",east,
            ORDER[2],
            ANGLEUNIT["degree",0.0174532925199433]],
    USAGE[
        SCOPE["unknown"],
        AREA["World"],
        BBOX[-90,-180,90,180]],
    ID["EPSG",4326]]

And it also works if I give a full string to the CRS() function

sp::CRS("+proj=sterea +lat_0=52.15616055555555 +lon_0=5.38763888888889 +k=0.9999079 +x_0=155000 +y_0=463000 +ellps=bessel +units=m +no_defs ")

CRS arguments:
 +proj=sterea +lat_0=52.1561605555556 +lon_0=5.38763888888889 +k=0.9999079 +x_0=155000 +y_0=463000
+ellps=bessel +units=m +no_defs 
Warning message:
In showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj = prefer_proj) :
  Discarded datum Unknown based on Bessel 1841 ellipsoid in Proj4 definition

I tried uninstalling and re installing the packages sp, raster, rgdal and rgeos but it didn't change my problem. My colleague who just updated everything also tried to run it but he didn't get any problem, so I thought it might come from my environment.

Here is my session

sessionInfo()
R version 4.0.3 (2020-10-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19041)

Matrix products: default

locale:
[1] LC_COLLATE=French_France.1252  LC_CTYPE=French_France.1252    LC_MONETARY=French_France.1252
[4] LC_NUMERIC=C                   LC_TIME=French_France.1252    

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

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.6         pillar_1.4.7       compiler_4.0.3     class_7.3-17       tools_4.0.3       
 [6] xts_0.12.1         gstat_2.0-6        lifecycle_0.2.0    tibble_3.0.6       lattice_0.20-41   
[11] FCF_0.0.0.9000     pkgconfig_2.0.3    rlang_0.4.10       DBI_1.1.1          rstudioapi_0.13   
[16] rgdal_1.5-23       e1071_1.7-4        dplyr_1.0.4        raster_3.4-5       generics_0.1.0    
[21] vctrs_0.3.6        classInt_0.4-3     grid_4.0.3         tidyselect_1.1.0   spacetime_1.2-4   
[26] glue_1.4.2         data.table_1.13.6  sf_0.9-7           R6_2.5.0           sp_1.4-5          
[31] tidyr_1.1.2        purrr_0.3.4        magrittr_2.0.1     intervals_0.15.2   codetools_0.2-16  
[36] ellipsis_0.3.1     units_0.6-7        rlist_0.4.6.1      assertthat_0.2.1   KernSmooth_2.23-17
[41] stringi_1.5.3      FNN_1.1.3          crayon_1.4.1       zoo_1.8-8

Here is my environment

Sys.getenv()
ALLUSERSPROFILE                   C:\ProgramData
APPDATA                           C:\Users\user\AppData\Roaming
CLICOLOR_FORCE                    1
CommonProgramFiles                C:\Program Files\Common Files
CommonProgramFiles(x86)           C:\Program Files (x86)\Common Files
CommonProgramW6432                C:\Program Files\Common Files
COMPUTERNAME                      DESKTOP-9J3P14F
ComSpec                           C:\WINDOWS\system32\cmd.exe
DISPLAY                           :0
DriverData                        C:\Windows\System32\Drivers\DriverData
ESET_OPTIONS                      
GDAL                              C:\Program Files\QGIS 3.10\share\gdal
GDAL_DATA                         C:/Users/user/Documents/R/win-library/4.0/sf/gdal
GFORTRAN_STDERR_UNIT              -1
GFORTRAN_STDOUT_UNIT              -1
HOME                              C:\Users\user\Documents
HOMEDRIVE                         C:
HOMEPATH                          \Users\user
LOCALAPPDATA                      C:\Users\user\AppData\Local
LOGONSERVER                       \\DESKTOP-9J3P14F
MPLENGINE                         tkAgg
MSYS2_ENV_CONV_EXCL               R_ARCH
NUMBER_OF_PROCESSORS              6
OneDrive                          C:\Users\user\OneDrive
OneDriveConsumer                  C:\Users\user\OneDrive
OS                                Windows_NT
PATH                              C:\rtools40\usr\bin;C:\Program Files\R\R-4.0.3\bin\x64;C:\Program
                                  Files (x86)\Common
                                  Files\Oracle\Java\javapath;C:\Rtools\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program
                                  Files\MiKTeX 2.9\miktex\bin\x64\;C:\Program Files
                                  (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program
                                  Files\Intel\Intel(R) Management Engine
                                  Components\DAL;C:\Users\user\AppData\Local\Microsoft\WindowsApps;C:\Program
                                  Files\MiKTeX
                                  2.9\miktex\bin\x64;C:\Users\user\AppData\Local\Programs\Microsoft VS
                                  Code\bin;C:\Users\user\AppData\Local\Microsoft\WindowsApps
PATHEXT                           .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
POSTGIS_ENABLE_OUTDB_RASTERS      1
POSTGIS_GDAL_ENABLED_DRIVERS      GTiff PNG JPEG GIF XYZ DTED USGSDEM AAIGrid
PROCESSOR_ARCHITECTURE            AMD64
PROCESSOR_IDENTIFIER              Intel64 Family 6 Model 158 Stepping 12, GenuineIntel
PROCESSOR_LEVEL                   6
PROCESSOR_REVISION                9e0c
ProgramData                       C:\ProgramData
ProgramFiles                      C:\Program Files
ProgramFiles(x86)                 C:\Program Files (x86)
ProgramW6432                      C:\Program Files
PROJ_LIB                          C:\Program Files\PostgreSQL\13\share\contrib\postgis-3.0\proj
PSModulePath                      C:\Program
                                  Files\WindowsPowerShell\Modules;C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules;C:\Program
                                  Files\Intel\Wired Networking\
PUBLIC                            C:\Users\Public
QT_D3DCREATE_MULTITHREADED        1
R_ARCH                            /x64
R_COMPILED_BY                     gcc 8.3.0
R_DOC_DIR                         C:/PROGRA~1/R/R-40~1.3/doc
R_HOME                            C:/PROGRA~1/R/R-40~1.3
R_LIBS_USER                       C:/Users/user/Documents/R/win-library/4.0
R_USER                            C:/Users/user/Documents
RMARKDOWN_MATHJAX_PATH            C:/Program Files/RStudio/resources/mathjax-27
RS_LOCAL_PEER                     \\.\pipe\23164-rsession
RS_RPOSTBACK_PATH                 C:/Program Files/RStudio/bin/rpostback
RS_SHARED_SECRET                  63341846741
RSTUDIO                           1
RSTUDIO_CONSOLE_COLOR             256
RSTUDIO_CONSOLE_WIDTH             80
RSTUDIO_MSYS_SSH                  C:/Program Files/RStudio/bin/msys-ssh-1000-18
RSTUDIO_PANDOC                    C:/Program Files/RStudio/bin/pandoc
RSTUDIO_PROGRAM_MODE              desktop
RSTUDIO_SESSION_PORT              23164
RSTUDIO_USER_IDENTITY             user
RSTUDIO_WINUTILS                  C:/Program Files/RStudio/bin/winutils
RTOOLS40_HOME                     C:\rtools40
SESSIONNAME                       Console
SystemDrive                       C:
SystemRoot                        C:\WINDOWS
TEMP                              C:\Users\user\AppData\Local\Temp
TERM                              xterm-256color
TMP                               C:\Users\user\AppData\Local\Temp
USERDOMAIN                        DESKTOP-9J3P14F
USERDOMAIN_ROAMINGPROFILE         DESKTOP-9J3P14F
USERNAME                          user
USERPROFILE                       C:\Users\user
windir                            C:\WINDOWS

I thought it might come from a failing link to some gdal directory with CRS data, so I tried to create a windows path to my gdal from QGIS, and then to tried to change my GDAL_DATA to the GDAL path, to the rgdal library path. When I first checked after this error the path was set to my PostgreSQL path.

None of those solutions seemed to work, and I couldn't find any similar questions on forums does anyone have some ideas?

3
  • Please show the output of rgdal::rgdal_extSoftVersion()
    – JRR
    Feb 12 '21 at 15:59
  • GDAL GDAL_with_GEOS PROJ sp "3.2.1" "TRUE" "7.2.1" "1.4-5"
    – Tristan
    Feb 15 '21 at 7:17
  • I tried uninstalling and reinstalling everything gdal or r related (Qgis, OSGeo, R, rtools, rstudio, postgres) following this procedure. R profile is correctly reset, but the problem remains : stackoverflow.com/questions/55204017/…
    – Tristan
    Feb 19 '21 at 11:16
4

I was able to get around the problem by using the sf::st_crs() function to transform in wkt, instead of directly using sp::CRS("+init=epsg:4326").

sp::CRS("+init=epsg:4326")

becomes

wkt <- sf::st_crs(4326)[[2]]
sp::CRS(wkt)

CRS arguments: +proj=longlat +datum=WGS84 +no_defs
1
  • I have had the same issue,, and resolved the same way! Any idea why was it happening? I have exactly the same output for rgdal::rgdal_extSoftVersion()
    – gacero
    Jun 14 '21 at 14:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.