Sf: full_join fails for sf

Created on 12 Dec 2018  路  4Comments  路  Source: r-spatial/sf

This worked for me before upgrading both dplyr and sf to the dev versions. The error occurs inside _dplyr_full_join_impl so it's hard for me to debug further.

library(tidyverse); library(sf)
#> Linking to GEOS 3.6.1, GDAL 2.2.3, PROJ 4.9.3
nc = read_sf(system.file("shape/nc.shp", package="sf"))

# sf fails  
nc %>% 
  full_join(tibble(CNTY_ID = 1))
#> Joining, by = "CNTY_ID"
#> Error: Evaluation error: 'names' attribute [101] must be the same length as the vector [100].

# plain list column works
nc %>%
  as.data.frame() %>% 
  as_tibble() %>% 
  mutate(geometry = unclass(geometry)) %>%
  full_join(tibble(CNTY_ID = 1))
#> Joining, by = "CNTY_ID"
#> # A tibble: 101 x 15
#>     AREA PERIMETER CNTY_ CNTY_ID NAME  FIPS  FIPSNO CRESS_ID BIR74 SID74
#>    <dbl>     <dbl> <dbl>   <dbl> <chr> <chr>  <dbl>    <int> <dbl> <dbl>
#>  1 0.114      1.44  1825    1825 Ashe  37009  37009        5  1091     1
#>  2 0.061      1.23  1827    1827 Alle~ 37005  37005        3   487     0
#>  3 0.143      1.63  1828    1828 Surry 37171  37171       86  3188     5
#>  4 0.07       2.97  1831    1831 Curr~ 37053  37053       27   508     1
#>  5 0.153      2.21  1832    1832 Nort~ 37131  37131       66  1421     9
#>  6 0.097      1.67  1833    1833 Hert~ 37091  37091       46  1452     7
#>  7 0.062      1.55  1834    1834 Camd~ 37029  37029       15   286     0
#>  8 0.091      1.28  1835    1835 Gates 37073  37073       37   420     0
#>  9 0.118      1.42  1836    1836 Warr~ 37185  37185       93   968     4
#> 10 0.124      1.43  1837    1837 Stok~ 37169  37169       85  1612     1
#> # ... with 91 more rows, and 5 more variables: NWBIR74 <dbl>, BIR79 <dbl>,
#> #   SID79 <dbl>, NWBIR79 <dbl>, geometry <list>

Created on 2018-12-13 by the reprex package (v0.2.1.9000)

library(tidyverse); library(sf)
#> Linking to GEOS 3.6.1, GDAL 2.2.3, PROJ 4.9.3
devtools::session_info() %>% 
  .[[2]] %>% 
  filter(package %in% c("dplyr", "sf"))
# A tibble: 2 x 11
  package ondiskversion loadedversion path                   loadedpath             attached is_base date       source                           md5ok library         
  <chr>   <chr>         <chr>         <chr>                  <chr>                  <lgl>    <lgl>   <chr>      <chr>                            <lgl> <fct>           
1 dplyr   0.7.99.9000   0.7.99.9000   C:/R/Library/3.5/dplyr C:/R/Library/3.5/dplyr TRUE     FALSE   2018-12-12 Github (tidyverse/dplyr@6e17633) NA    C:/R/Library/3.5
2 sf      0.7.2         0.7-2         C:/R/Library/3.5/sf    C:/R/Library/3.5/sf    TRUE     FALSE   2018-12-10 Github (r-spatial/sf@bb53f02)    NA    C:/R/Library/3.5
> 

Created on 2018-12-13 by the reprex package (v0.2.1.9000)

Most helpful comment

Thanks. Can one of you open an issue in dplyr ?

All 4 comments

Confirmed that reverting to CRAN dplyr fixes this problem. @romainfrancois, FYI

Thanks. Can one of you open an issue in dplyr ?

Done. Will close this for now.

Need to make [.sfc work with NA indexes; see https://github.com/tidyverse/dplyr/issues/4016

Was this page helpful?
0 / 5 - 0 ratings