vctrs icon indicating copy to clipboard operation
vctrs copied to clipboard

`rbind` error when using `add_row` on `sf` objects

Open bart1 opened this issue 2 years ago • 3 comments

I'm not sure if this is an error of the vctrs implementation in sf or a problem in vtrcs, as the suggestion is to report it here I'll do that first. The error occurs when 0 rows are added to an sf data.frame (as part of code where the number of rows added is variable).

require(sf)
require(dplyr)
g<-data.frame(a=1, x=1,y=4)
add_row(g, a=numeric())
#>   a x y
#> 1 1 1 4
g<-st_as_sf(data.frame(a=1, x=1,y=4), coords = 2:3)
add_row(g, a=6)
#> Simple feature collection with 2 features and 1 field (with 1 geometry empty)
#> Geometry type: POINT
#> Dimension:     XY
#> Bounding box:  xmin: 1 ymin: 4 xmax: 1 ymax: 4
#> CRS:           NA
#>   a    geometry
#> 1 1 POINT (1 4)
#> 2 6 POINT EMPTY
add_row(g, a=numeric())
#> Error in `vec_rbind()`:
#> ! `c()` method returned a vector of unexpected size 3 instead of 1.
#> ℹ In file 'c.c' at line 412.
#> ℹ This is an internal error that was detected in the vctrs package.
#>   Please report it at <https://github.com/r-lib/vctrs/issues> with a reprex (<https://https://tidyverse.org/help/>) and the full backtrace.

#> Backtrace:
#>     ▆
#>  1. ├─tibble::add_row(g, a = numeric())
#>  2. │ └─tibble:::rbind_at(.data, df, pos)
#>  3. │   └─vctrs::vec_rbind(old, new)
#>  4. └─rlang:::stop_internal_c_lib(...)
#>  5.   └─rlang::abort(message, call = call, .internal = TRUE, .frame = frame)
sessionInfo()
#> R version 4.2.2 Patched (2022-11-10 r83330)
#> Platform: x86_64-pc-linux-gnu (64-bit)
#> Running under: Ubuntu 20.04.5 LTS
#> 
#> Matrix products: default
#> BLAS:   /usr/lib/x86_64-linux-gnu/atlas/libblas.so.3.10.3
#> LAPACK: /usr/lib/x86_64-linux-gnu/atlas/liblapack.so.3.10.3
#> 
#> locale:
#>  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
#>  [3] LC_TIME=nl_NL.UTF-8        LC_COLLATE=en_US.UTF-8    
#>  [5] LC_MONETARY=nl_NL.UTF-8    LC_MESSAGES=en_US.UTF-8   
#>  [7] LC_PAPER=nl_NL.UTF-8       LC_NAME=C                 
#>  [9] LC_ADDRESS=C               LC_TELEPHONE=C            
#> [11] LC_MEASUREMENT=nl_NL.UTF-8 LC_IDENTIFICATION=C       
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> other attached packages:
#> [1] dplyr_1.0.10 sf_1.0-9    
#> 
#> loaded via a namespace (and not attached):
#>  [1] Rcpp_1.0.9         pillar_1.8.1       compiler_4.2.2     highr_0.9         
#>  [5] class_7.3-20       R.methodsS3_1.8.2  R.utils_2.12.0     tools_4.2.2       
#>  [9] digest_0.6.29      evaluate_0.17      lifecycle_1.0.3    tibble_3.1.8      
#> [13] R.cache_0.16.0     pkgconfig_2.0.3    rlang_1.0.6        reprex_2.0.2      
#> [17] cli_3.4.1          DBI_1.1.3          rstudioapi_0.14    yaml_2.3.6        
#> [21] xfun_0.33          fastmap_1.1.0      e1071_1.7-12       withr_2.5.0       
#> [25] styler_1.7.0       stringr_1.4.1      knitr_1.40         generics_0.1.3    
#> [29] fs_1.5.2           vctrs_0.5.1        tidyselect_1.2.0   grid_4.2.2        
#> [33] classInt_0.4-8     glue_1.6.2         R6_2.5.1           winch_0.0.11      
#> [37] fansi_1.0.3        rmarkdown_2.17     purrr_0.3.5        magrittr_2.0.3    
#> [41] units_0.8-0        htmltools_0.5.3    assertthat_0.2.1   KernSmooth_2.23-20
#> [45] utf8_1.2.2         stringi_1.7.8      proxy_0.4-27       R.oo_1.25.0

Created on 2022-11-25 with reprex v2.0.2

bart1 avatar Nov 25 '22 12:11 bart1