Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sf 0.6-1 (CRAN): plot error #685

Closed
Nowosad opened this issue Mar 23, 2018 · 6 comments
Closed

sf 0.6-1 (CRAN): plot error #685

Nowosad opened this issue Mar 23, 2018 · 6 comments

Comments

@Nowosad
Copy link
Contributor

Nowosad commented Mar 23, 2018

The new sf version give an error when plotting a simple dataset - world (epsg: 4326).
The code and session info are attached below:

library(sf)    
#> Linking to GEOS 3.6.1, GDAL 2.1.4, proj.4 4.9.3
library(spData)
plot(world)    
#> Warning in if (is.na(x)) NA_crs_ else if (inherits(x, "crs")) x else if
#> (is.numeric(x)) CPL_crs_from_epsg(as.integer(x)) else if (is.character(x))
#> {: the condition has length > 1 and only the first element will be used
#> Error in CPL_crs_from_epsg(as.integer(x)): Expecting a single value: [extent=4].
Session info
devtools::session_info()
#> Session info -------------------------------------------------------------
#>  setting  value                       
#>  version  R version 3.4.3 (2017-11-30)
#>  system   x86_64, linux-gnu           
#>  ui       X11                         
#>  language (EN)                        
#>  collate  en_US.UTF-8                 
#>  tz       America/New_York            
#>  date     2018-03-23
#> Packages -----------------------------------------------------------------
#>  package     * version date       source                              
#>  backports     1.1.2   2017-12-13 CRAN (R 3.4.2)                      
#>  base        * 3.4.3   2017-11-30 local                               
#>  class         7.3-14  2015-08-30 CRAN (R 3.4.3)                      
#>  classInt      0.1-24  2017-04-16 CRAN (R 3.4.3)                      
#>  compiler      3.4.3   2017-11-30 local                               
#>  datasets    * 3.4.3   2017-11-30 local                               
#>  DBI           0.8     2018-03-02 cran (@0.8)                         
#>  devtools      1.13.5  2018-02-18 CRAN (R 3.4.3)                      
#>  digest        0.6.15  2018-01-28 cran (@0.6.15)                      
#>  e1071         1.6-8   2017-02-02 cran (@1.6-8)                       
#>  evaluate      0.10.1  2017-06-24 cran (@0.10.1)                      
#>  graphics    * 3.4.3   2017-11-30 local                               
#>  grDevices   * 3.4.3   2017-11-30 local                               
#>  grid          3.4.3   2017-11-30 local                               
#>  htmltools     0.3.6   2017-04-28 CRAN (R 3.4.0)                      
#>  knitr         1.20    2018-02-20 cran (@1.20)                        
#>  magrittr      1.5     2014-11-22 CRAN (R 3.4.0)                      
#>  memoise       1.1.0   2017-04-21 CRAN (R 3.4.0)                      
#>  methods     * 3.4.3   2017-11-30 local                               
#>  Rcpp          0.12.16 2018-03-13 CRAN (R 3.4.3)                      
#>  rmarkdown     1.9     2018-03-01 CRAN (R 3.4.3)                      
#>  rprojroot     1.3-2   2018-01-03 CRAN (R 3.4.2)                      
#>  sf          * 0.6-1   2018-03-22 cran (@0.6-1)                       
#>  spData      * 0.2.8.2 2018-03-23 Github (nowosad/spData@fc139b6)     
#>  spDataLarge   0.2.6.0 2018-03-09 Github (nowosad/spDataLarge@bfb1db6)
#>  stats       * 3.4.3   2017-11-30 local                               
#>  stringi       1.1.7   2018-03-12 cran (@1.1.7)                       
#>  stringr       1.3.0   2018-02-19 cran (@1.3.0)                       
#>  tools         3.4.3   2017-11-30 local                               
#>  udunits2      0.13    2016-11-17 CRAN (R 3.4.0)                      
#>  units         0.5-1   2018-01-08 cran (@0.5-1)                       
#>  utils       * 3.4.3   2017-11-30 local                               
#>  withr         2.1.2   2018-03-17 Github (jimhester/withr@79d7b0d)    
#>  yaml          2.1.18  2018-03-08 CRAN (R 3.4.3)
@edzer
Copy link
Member

edzer commented Mar 23, 2018

Thanks!

> class(st_bbox(nc))
[1] "bbox"
> class(st_bbox(world))
[1] "numeric"

so the way bounding boxes are stored in sf objects has changed. And when retrieving, st_bbox doesn't set the class attribute.

@edzer
Copy link
Member

edzer commented Mar 23, 2018

Ah, this may also affect bcmaps and bcmaps.rdata, @ateucher .

@Nowosad
Copy link
Contributor Author

Nowosad commented Mar 23, 2018

It probably affects several R packages - I would assume that some of the reverse depends/imports/suggests packages also contains some sf data - https://cran.r-project.org/web/packages/sf/index.html.

Is there a way to fix existing data? I've (naively) tried class(st_bbox(world)) = "bbox", but it doesn't work.

@edzer
Copy link
Member

edzer commented Mar 23, 2018

Yes, rerunning the script you used to create the object in the first place with 0.6-1, or alternatively,

set_bb = function(x) { class(attr(x[[attr(x, "sf_column")]], "bbox")) = "bbox"; x }
(world = set_bb(world))

@ateucher
Copy link
Contributor

ateucher commented Mar 23, 2018

Thanks for the heads up @edzer. This doesn't seem to affect bcmaps/bcmaps.rdata (though why I don't know?) Or maybe it will if I were to recreate the data with the current version of sf?:

library(sf)
#> Linking to GEOS 3.6.2, GDAL 2.2.3, proj.4 5.0.0
library(bcmaps)
library(spData)
#> To access larger datasets in this package, install the spDataLarge
#> package with: `install.packages('spDataLarge',
#> repos='https://nowosad.github.io/drat/', type='source'))`

class(st_bbox(world))
#> [1] "numeric"
class(st_bbox(bc_bound()))
#> [1] "bbox"

Created on 2018-03-23 by the reprex package (v0.2.0).

@Nowosad
Copy link
Contributor Author

Nowosad commented Mar 24, 2018

I've checked all the sf data in my packages. It turns out that this issue affects only objects older that ~6 months.
Thanks for the solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants