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

Use list-columns as alternative to tm_mv for multivariate variables #898

Open
MatthieuStigler opened this issue Jul 7, 2024 · 2 comments

Comments

@MatthieuStigler
Copy link
Contributor

MatthieuStigler commented Jul 7, 2024

I am getting a strange error message running a very simple call tm_shape(inter)+ tm_borders():

Error in sort.int(x, na.last = na.last, decreasing = decreasing, ...) : 'x' must be atomic

I suspect it happens whenever a sf object contains a list column? See example below, where the code will break when inter has list-column origins, but run if origins is removed?

library(sf)
#> Linking to GEOS 3.10.2, GDAL 3.4.3, PROJ 8.2.0; sf_use_s2() is TRUE
library(tmap)
#> 
#> Attaching package: 'tmap'
#> The following object is masked from 'package:datasets':
#> 
#>     rivers
packageVersion("tmap")
#> [1] '3.99.9001'
packageVersion("sf")
#> [1] '1.0.16'
col <- st_sfc(st_polygon(list(rbind(c(-1, 2), c(11, 2), c(11, 4), c(-1, 4), c(-1, 2)))),
      st_polygon(list(rbind(c(-1, 2), c(11, 2), c(11, 4), c(-1, 4), c(-1, 2))))) %>% 
  st_as_sf()

inter <- st_intersection(col)

tm_shape(inter)+
  tm_borders()
#> Error in sort.int(x, na.last = na.last, decreasing = decreasing, ...): 'x' must be atomic
## works:
# tm_shape(inter %>% select(-origins))+
#   tm_borders()

Created on 2024-07-07 with reprex v2.1.0

@Nowosad Nowosad added the bug label Jul 7, 2024
@mtennekes
Copy link
Member

Interesting example, thanks @MatthieuStigler

Not sure what to do with list columns. We ignore them. (Which is sufficient for your example) For the time being I'll do that.

A potential use case would be to use instead of tm_mv, to give the users more flexibility.

@mtennekes
Copy link
Member

Done. I'll rename this issue

@mtennekes mtennekes reopened this Jul 16, 2024
@mtennekes mtennekes added enhancement and removed bug labels Jul 16, 2024
@mtennekes mtennekes changed the title tmap v4 fails if data contains list-column? Error in sort.int(x, na.last = na.last, decreasing = decreasing, ...) : 'x' must be atomic Use list-columns as alternative to tm_mv for multivariate variables Jul 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants