Skip to content

Unrecognized CRS in RStudio console, functions as expected in Terminal #10052

Closed

Description

@tylerdrudolph

System details

RStudio Edition : Desktop
RStudio Version : 2021.09.0 Build 351
OS Version      : Windows 10 x64 (build 19042)
R Version       : R version 4.1.2 (2021-11-01)

Describe the problem in detail

Defining a legitimate Coordinate Reference System (CRS) in the RStudio Console draws an unexpected error that does not occur when run in the Terminal. See rspatial/raster#232 for background on this issue.

Steps to reproduce the problem

From the RStudio Console in a clean new project:

> library(raster)
# Loading required package: sp
> x <- raster(xmn=273366.5, xmx=1870587, ymn=359771.8, ymx=1735721, crs="EPSG:3005")
# Error in sp::CRS(SRS_string = x) : NA
>crs(x)
# CRS arguments: NA

From the RStudio Terminal:

> library(raster)
#Loading required package: sp
> x <- raster(xmn=273366.5, xmx=1870587, ymn=359771.8, ymx=1735721, crs="EPSG:$
> writeRaster(x, driver='GTiff', filename='x.tif', overwrite=T)
# Warning message:
# In .local(x, filename, ...) : all cell values are NA
> crs(x)
# CRS arguments:
 +proj=aea +lat_0=45 +lon_0=-126 +lat_1=50 +lat_2=58.5 +x_0=1000000
+y_0=0 +datum=NAD83 +units=m +no_defs

Describe the behavior you expected

The following result should occur whether invoked from RStudio or directly from within R:

> sp::CRS("EPSG:3005")`
# CRS arguments:
 +proj=aea +lat_0=45 +lon_0=-126 +lat_1=50 +lat_2=58.5 +x_0=1000000
+y_0=0 +datum=NAD83 +units=m +no_defs

What the call returns instead is the following error:

> sp::CRS("EPSG:3005")
# Error in sp::CRS("EPSG:3005") : NA
  • [x ] I have read the guide for submitting good bug reports.
  • [ x] I have installed the latest version of RStudio, and confirmed that the issue still persists.
  • [ x] If I am reporting an RStudio crash, I have included a diagnostics report.
  • [ x] I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.

Activity

  1. kevinushey commented on Nov 5, 2021

    @kevinushey
    Collaborator

    I see the same behavior with RGui 4.1.1, and I also see the same behavior in an R process launched as a child from an RStudio session, so I don't think this is specific to RStudio.

    library(raster)
    
    x <- raster(
      xmn = 273366.5,
      xmx = 1870587,
      ymn = 359771.8,
      ymx = 1735721,
      crs = "EPSG:3005"
    )
    
    crs(x)
    
  2. tylerdrudolph commented on Nov 5, 2021

    @tylerdrudolph
    Author

    @kevinushey I am seeing this problem recurring in Rterm as well now.
    Closing this for the time being and re-opening rspatial/raster#232.

  3. tylerdrudolph commented on Nov 19, 2021

    @tylerdrudolph
    Author

    This issue still occurs with the latest versions of R, sp package and RStudio. The problem only occurs in the RStudio Console. When R is run in the terminal it performs as expected.

    ################
    # In RStudio Terminal
    C:\Users\user1\Documents>R
    
    R version 4.1.2 (2021-11-01) -- "Bird Hippie"
    Copyright (C) 2021 The R Foundation for Statistical Computing
    Platform: x86_64-w64-mingw32/x64 (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.
    
    > sp::CRS("EPSG:3005")
    CRS arguments:
     +proj=aea +lat_0=45 +lon_0=-126 +lat_1=50 +lat_2=58.5 +x_0=1000000
    +y_0=0 +datum=NAD83 +units=m +no_defs
    
    ###############
    # In RStudio Console
    > sp::CRS("EPSG:3005")
    Error in sp::CRS("EPSG:3005") : NA
    
  4. tylerdrudolph commented on Nov 22, 2021

    @tylerdrudolph
    Author

    Any idea at RStudio as to what might be causing this? Or suggestions as to what I might try next?

    @kevinushey are you still encountering this problem? Does the following fail in both R and Studio Console?

    sp:CRS("EPSG:3005")
    
  5. kevinushey commented on Feb 3, 2022

    @kevinushey
    Collaborator

    This is what I'm seeing now:

    > x <- raster(
    +   xmn = 273366.5,
    +   xmx = 1870587,
    +   ymn = 359771.8,
    +   ymx = 1735721,
    +   crs = "EPSG:3005"
    + )
    > crs(x)
    Coordinate Reference System:
    Deprecated Proj.4 representation: NA 
    Warning message:
    In wkt(x) : CRS object has no comment
    

    However, the issue went away after I installed the rgdal R package, e.g. with

    install.packages("rgdal")
    

    (and then restarting R and re-running the example).

    So it seems like the behavior here somehow depends on the rgdal package being installed, at least for me.

  6. github-actions commented on Aug 3, 2022

    @github-actions

    This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs, per https://github.com/rstudio/rstudio/wiki/Issue-Grooming. Thank you for your contributions.

  7. added
    stale
    on Aug 3, 2022
  8. tylerdrudolph commented on Aug 3, 2022

    @tylerdrudolph
    Author

    This issue no longer occurs for me since migrating all programs from rgdal/raster/sp toward sf, terra and gdalUtilities.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugconsolestale

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions