wfmackey / absmapsdata

Use ABS ASGS data easily in R
58 stars 18 forks source link

Can't join sfc to tibbles #20

Closed jamesha95 closed 4 years ago

jamesha95 commented 4 years ago

After updating tidyverse, it seems that sfc objects can no longer by left_join'd to tibbles, only data.frames.

tribble(~x,         ~y, 
        "Melbourne", 1, 
        "Docklands", 5) %>% 
  left_join(sa22016, by = c('x' = 'sa2_name_2016'))

leads to Error: Input must be a vector, not a sfc_MULTIPOLYGON/sfc object.

But

data.frame(x= c("Melbourne", "Docklands"), y = c(1, 5)) %>% 
  left_join(sa22016, by = c('x' = 'sa2_name_2016'))

seems to work.

wfmackey commented 4 years ago

hmm can't reproduce that error after updating tidyverse:

library(tidyverse)
library(absmapsdata)
library(sf)
#> Linking to GEOS 3.7.2, GDAL 2.4.2, PROJ 5.2.0

tribble(~x,         ~y, 
        "Melbourne", 1, 
        "Docklands", 5) %>% 
  left_join(sa22016, by = c('x' = 'sa2_name_2016'))
#> # A tibble: 2 x 16
#>   x         y sa2_main_2016 sa2_5dig_2016 sa3_code_2016 sa3_name_2016
#> * <chr> <dbl> <chr>         <chr>         <chr>         <chr>        
#> 1 Melb…     1 206041122     21122         20604         Melbourne Ci…
#> 2 Dock…     5 206041118     21118         20604         Melbourne Ci…
#> # … with 10 more variables: sa4_code_2016 <chr>, sa4_name_2016 <chr>,
#> #   gcc_code_2016 <chr>, gcc_name_2016 <chr>, state_code_2016 <chr>,
#> #   state_name_2016 <chr>, areasqkm_2016 <dbl>, cent_long <dbl>,
#> #   cent_lat <dbl>, geometry <MULTIPOLYGON [°]>

Created on 2020-04-23 by the reprex package (v0.3.0)

Session info ``` r devtools::session_info() #> ─ Session info ─────────────────────────────────────────────────────────────── #> setting value #> version R version 3.6.3 (2020-02-29) #> os macOS Catalina 10.15.3 #> system x86_64, darwin15.6.0 #> ui X11 #> language (EN) #> collate en_AU.UTF-8 #> ctype en_AU.UTF-8 #> tz Australia/Melbourne #> date 2020-04-23 #> #> ─ Packages ─────────────────────────────────────────────────────────────────── #> package * version date lib source #> absmapsdata * 1.2.1 2020-04-15 [1] Github (wfmackey/absmapsdata@8f49693) #> assertthat 0.2.1 2019-03-21 [2] CRAN (R 3.6.0) #> backports 1.1.6 2020-04-05 [1] CRAN (R 3.6.2) #> broom 0.5.6 2020-04-20 [1] CRAN (R 3.6.2) #> callr 3.4.3 2020-03-28 [1] CRAN (R 3.6.2) #> cellranger 1.1.0 2016-07-27 [2] CRAN (R 3.6.0) #> class 7.3-15 2019-01-01 [2] CRAN (R 3.6.3) #> classInt 0.4-2 2019-10-17 [1] CRAN (R 3.6.0) #> cli 2.0.2 2020-02-28 [1] CRAN (R 3.6.0) #> colorspace 1.4-1 2019-03-18 [2] CRAN (R 3.6.0) #> crayon 1.3.4 2017-09-16 [2] CRAN (R 3.6.0) #> DBI 1.1.0 2019-12-15 [1] CRAN (R 3.6.0) #> dbplyr 1.4.3 2020-04-19 [1] CRAN (R 3.6.2) #> desc 1.2.0 2018-05-01 [2] CRAN (R 3.6.0) #> devtools 2.3.0 2020-04-10 [1] CRAN (R 3.6.2) #> digest 0.6.25 2020-02-23 [1] CRAN (R 3.6.0) #> dplyr * 0.8.99.9002 2020-04-23 [1] Github (tidyverse/dplyr@b6e5c5c) #> e1071 1.7-3 2019-11-26 [1] CRAN (R 3.6.0) #> ellipsis 0.3.0 2019-09-20 [1] CRAN (R 3.6.0) #> evaluate 0.14 2019-05-28 [2] CRAN (R 3.6.0) #> fansi 0.4.1 2020-01-08 [1] CRAN (R 3.6.0) #> forcats * 0.5.0 2020-03-01 [1] CRAN (R 3.6.0) #> fs 1.4.1 2020-04-04 [1] CRAN (R 3.6.2) #> generics 0.0.2 2018-11-29 [2] CRAN (R 3.6.0) #> ggplot2 * 3.3.0 2020-03-05 [1] CRAN (R 3.6.0) #> glue 1.4.0 2020-04-03 [1] CRAN (R 3.6.0) #> gtable 0.3.0 2019-03-25 [2] CRAN (R 3.6.0) #> haven 2.2.0 2019-11-08 [1] CRAN (R 3.6.0) #> highr 0.8 2019-03-20 [2] CRAN (R 3.6.0) #> hms 0.5.3 2020-01-08 [1] CRAN (R 3.6.0) #> htmltools 0.4.0 2019-10-04 [1] CRAN (R 3.6.0) #> httr 1.4.1 2019-08-05 [1] CRAN (R 3.6.0) #> jsonlite 1.6.1 2020-02-02 [1] CRAN (R 3.6.0) #> KernSmooth 2.23-16 2019-10-15 [2] CRAN (R 3.6.3) #> knitr 1.28 2020-02-06 [1] CRAN (R 3.6.0) #> lattice 0.20-38 2018-11-04 [2] CRAN (R 3.6.3) #> lifecycle 0.2.0 2020-03-06 [1] CRAN (R 3.6.0) #> lubridate 1.7.8 2020-04-06 [1] CRAN (R 3.6.2) #> magrittr 1.5 2014-11-22 [2] CRAN (R 3.6.0) #> memoise 1.1.0 2017-04-21 [2] CRAN (R 3.5.0) #> modelr 0.1.6 2020-02-22 [1] CRAN (R 3.6.0) #> munsell 0.5.0 2018-06-12 [2] CRAN (R 3.6.0) #> nlme 3.1-144 2020-02-06 [2] CRAN (R 3.6.3) #> pillar 1.4.3 2019-12-20 [1] CRAN (R 3.6.0) #> pkgbuild 1.0.6 2019-10-09 [1] CRAN (R 3.6.0) #> pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 3.6.0) #> pkgload 1.0.2 2018-10-29 [2] CRAN (R 3.6.0) #> prettyunits 1.1.1 2020-01-24 [1] CRAN (R 3.6.0) #> processx 3.4.2 2020-02-09 [1] CRAN (R 3.6.0) #> ps 1.3.2 2020-02-13 [1] CRAN (R 3.6.0) #> purrr * 0.3.4 2020-04-17 [1] CRAN (R 3.6.2) #> R6 2.4.1 2019-11-12 [1] CRAN (R 3.6.0) #> Rcpp 1.0.4.6 2020-04-09 [1] CRAN (R 3.6.0) #> readr * 1.3.1 2018-12-21 [2] CRAN (R 3.6.0) #> readxl 1.3.1 2019-03-13 [2] CRAN (R 3.6.0) #> remotes 2.1.1 2020-02-15 [1] CRAN (R 3.6.0) #> reprex 0.3.0 2019-05-16 [2] CRAN (R 3.6.0) #> rlang 0.4.5.9000 2020-04-08 [1] Github (r-lib/rlang@a90b04b) #> rmarkdown 2.1 2020-01-20 [1] CRAN (R 3.6.0) #> rprojroot 1.3-2 2018-01-03 [2] CRAN (R 3.5.0) #> rvest 0.3.5 2019-11-08 [1] CRAN (R 3.6.0) #> scales 1.1.0 2019-11-18 [1] CRAN (R 3.6.0) #> sessioninfo 1.1.1 2018-11-05 [2] CRAN (R 3.6.0) #> sf * 0.9-2 2020-04-14 [1] CRAN (R 3.6.2) #> stringi 1.4.6 2020-02-17 [1] CRAN (R 3.6.0) #> stringr * 1.4.0 2019-02-10 [2] CRAN (R 3.6.0) #> testthat 2.3.2 2020-03-02 [1] CRAN (R 3.6.0) #> tibble * 3.0.1 2020-04-20 [1] CRAN (R 3.6.2) #> tidyr * 1.0.2 2020-01-24 [1] CRAN (R 3.6.0) #> tidyselect 1.0.0 2020-01-27 [1] CRAN (R 3.6.0) #> tidyverse * 1.3.0.9000 2020-04-23 [1] Github (tidyverse/tidyverse@1d7f9b7) #> units 0.6-5 2019-10-08 [1] CRAN (R 3.6.0) #> usethis 1.6.0 2020-04-09 [1] CRAN (R 3.6.2) #> utf8 1.1.4 2018-05-24 [2] CRAN (R 3.6.0) #> vctrs 0.2.99.9011 2020-04-23 [1] Github (r-lib/vctrs@bf44281) #> withr 2.2.0 2020-04-20 [1] CRAN (R 3.6.2) #> xfun 0.13 2020-04-13 [1] CRAN (R 3.6.2) #> xml2 1.3.1 2020-04-09 [1] CRAN (R 3.6.2) #> yaml 2.2.1 2020-02-01 [1] CRAN (R 3.6.0) #> #> [1] /Users/mackeyw/Library/R/3.6/library #> [2] /Library/Frameworks/R.framework/Versions/3.6/Resources/library ```
mdsumner commented 4 years ago

@jamesha95 it might be that you did it without loading sf? There's a vec_proxy thing in sf that makes tibble see the geometry column as an actual list, i.e. class == c("sfc_MULTIPOLYGON", "sfc", "list")

and the new tibble requires that. (just so you know, it seemed pretty obscure to me before I knew)

jamesha95 commented 4 years ago

Ah yep, that solved it. Many thanks!