Error on attribute joins with different variable names
Closed this issue · 2 comments
dpprdan commented
In dplyr
's documentation for join
it says
by [...]
To join by different variables on x and y use a named vector.
For example, by = c("a" = "b") will match x.a to y.b.
However, this is not supported by sf at the moment:
library("dplyr", warn.conflicts = FALSE)
library("sf")
#> Linking to GEOS 3.6.1, GDAL 2.2.0, proj.4 4.9.3
nc_sf <- st_read(system.file("shape/nc.shp", package="sf"), quiet = TRUE)
nc_df <- nc_sf %>% st_set_geometry(NULL) %>% rename(fips = FIPS)
left_join(nc_sf, nc_df, by = ("FIPS" = "fips"))
#> Error: `by` can't contain join column `fips` which is missing from LHS
Session info
devtools::session_info()
#> Session info -------------------------------------------------------------
#> setting value
#> version R version 3.4.1 (2017-06-30)
#> system x86_64, mingw32
#> ui RTerm
#> language (EN)
#> collate German_Germany.1252
#> tz Europe/Berlin
#> date 2017-07-12
#> Packages -----------------------------------------------------------------
#> package * version date source
#> assertthat 0.2.0 2017-04-11 CRAN (R 3.3.3)
#> backports 1.1.0 2017-05-22 CRAN (R 3.4.0)
#> base * 3.4.1 2017-06-30 local
#> bindr 0.1 2016-11-13 CRAN (R 3.4.0)
#> bindrcpp 0.2 2017-06-17 CRAN (R 3.4.0)
#> compiler 3.4.1 2017-06-30 local
#> datasets * 3.4.1 2017-06-30 local
#> DBI 0.7 2017-06-18 CRAN (R 3.4.0)
#> devtools 1.13.2 2017-06-02 CRAN (R 3.4.0)
#> digest 0.6.12 2017-01-27 CRAN (R 3.3.2)
#> dplyr * 0.7.1 2017-06-22 CRAN (R 3.4.0)
#> evaluate 0.10.1 2017-06-24 CRAN (R 3.4.0)
#> glue 1.1.1 2017-06-21 CRAN (R 3.4.0)
#> graphics * 3.4.1 2017-06-30 local
#> grDevices * 3.4.1 2017-06-30 local
#> grid 3.4.1 2017-06-30 local
#> htmltools 0.3.6 2017-04-28 CRAN (R 3.4.0)
#> knitr 1.16 2017-05-18 CRAN (R 3.4.0)
#> magrittr 1.5 2014-11-22 CRAN (R 3.3.0)
#> memoise 1.1.0 2017-05-29 Github (hadley/memoise@e372cde)
#> methods * 3.4.1 2017-06-30 local
#> pkgconfig 2.0.1 2017-03-21 CRAN (R 3.4.0)
#> R6 2.2.2 2017-06-17 CRAN (R 3.4.0)
#> Rcpp 0.12.11 2017-05-22 CRAN (R 3.4.0)
#> rlang 0.1.1 2017-05-18 CRAN (R 3.4.0)
#> rmarkdown 1.6 2017-06-15 CRAN (R 3.4.0)
#> rprojroot 1.2 2017-01-16 CRAN (R 3.3.2)
#> sf * 0.5-2 2017-07-12 Github (edzer/sfr@f7635f7)
#> stats * 3.4.1 2017-06-30 local
#> stringi 1.1.5 2017-04-07 CRAN (R 3.3.3)
#> stringr 1.2.0 2017-02-18 CRAN (R 3.3.3)
#> tibble 1.3.3 2017-05-28 CRAN (R 3.4.0)
#> tools 3.4.1 2017-06-30 local
#> udunits2 0.13 2016-11-17 CRAN (R 3.3.2)
#> units 0.4-5 2017-06-15 CRAN (R 3.4.0)
#> utils * 3.4.1 2017-06-30 local
#> withr 1.0.2 2016-06-20 CRAN (R 3.3.1)
#> yaml 2.1.14 2016-11-12 CRAN (R 3.3.2)
edzer commented
Try
left_join(nc_sf, nc_df, by = c("FIPS" = "fips"))
(note the c
)
dpprdan commented
🤦
👍