-
Notifications
You must be signed in to change notification settings - Fork 66
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
rbind
error when using add_row
on sf
objects
#1748
Comments
Same here with Sys.setenv(LANGUAGE="en")
a=tibble::tibble(y=package_version("1.0.0"))
b=tibble::tibble(x=character(0))
dplyr::bind_rows(a, b)
#> Warning in y[bad] <- rep.int(list(integer()), length(bad)): number of items to
#> replace is not a multiple of replacement length
#> Error in `vec_rbind()`:
#> ! `c()` method returned a vector of unexpected size 3 instead of 1.
#> i In file 'c.c' at line 414.
#> i 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://tidyverse.org/help/>) and the full backtrace.
#> Backtrace:
#> x
#> 1. +-dplyr::bind_rows(a, b)
#> 2. | \-vctrs::vec_rbind(!!!dots, .names_to = .id, .error_call = current_env())
#> 3. \-rlang:::stop_internal_c_lib(...)
#> 4. \-rlang::abort(message, call = call, .internal = TRUE, .frame = frame) Created on 2023-05-05 with reprex v2.0.2 Oddly, I don't get the |
Also seeing this, however for me it is caused by binding 2 tibbles where only 1 has a geometry column and either tibble is empty: df1 <- tibble::tibble(
ref = c("143_2", "143_2", "143_2", "143_2", "143_2"),
block = c("206/3", "217/8", "206/3", "206/3", "217/8"),
date = structure(c(19448, 19449, 19449, 19450, 19451), class = "Date")
)
df2 <- tibble::tibble(
ref = character(0),
latitude = numeric(0),
longitude = numeric(0),
date = structure(numeric(0), class = "Date"),
geometry = sf::st_sfc(crs = 4326)
)
dplyr::bind_rows(df1, df2)
#> Error in `vec_rbind()`:
#> ! `c()` method returned a vector of unexpected size 6 instead of 5.
#> ℹ 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://tidyverse.org/help/>) and the full backtrace. Created on 2023-07-21 by the reprex package (v2.0.0) df1 <- tibble::tibble(
ref = c("143_2", "143_2", "143_2", "143_2", "143_2"),
block = c("206/3", "217/8", "206/3", "206/3", "217/8"),
date = structure(c(19448, 19449, 19449, 19450, 19451), class = "Date"),
geometry = sf::st_sfc(sf::st_polygon(), crs = 4326)
)
df2 <- tibble::tibble(
ref = character(0),
latitude = numeric(0),
longitude = numeric(0),
date = structure(numeric(0), class = "Date")
)
dplyr::bind_rows(df1, df2)
#> Error in `vec_rbind()`:
#> ! `c()` method returned a vector of unexpected size 7 instead of 5.
#> ℹ 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://tidyverse.org/help/>) and the full backtrace. Created on 2023-07-21 by the reprex package (v2.0.0) df1 <- tibble::tibble(
ref = c("143_2", "143_2", "143_2", "143_2", "143_2"),
block = c("206/3", "217/8", "206/3", "206/3", "217/8"),
date = structure(c(19448, 19449, 19449, 19450, 19451), class = "Date"),
geometry = sf::st_sfc(sf::st_polygon(), crs = 4326)
)
df2 <- tibble::tibble(
ref = character(0),
latitude = numeric(0),
longitude = numeric(0),
date = structure(numeric(0), class = "Date"),
geometry = sf::st_sfc(crs = 4326)
)
dplyr::bind_rows(df1, df2)
#> # A tibble: 5 × 6
#> ref block date geometry latitude longitude
#> <chr> <chr> <date> <POLYGON [°]> <dbl> <dbl>
#> 1 143_2 206/3 2023-04-01 EMPTY NA NA
#> 2 143_2 217/8 2023-04-02 EMPTY NA NA
#> 3 143_2 206/3 2023-04-02 EMPTY NA NA
#> 4 143_2 206/3 2023-04-03 EMPTY NA NA
#> 5 143_2 217/8 2023-04-04 EMPTY NA NA Created on 2023-07-21 by the reprex package (v2.0.0) |
I get this error when binding a tibble with some rows to a spatial data frame with 0 rows: library(tibble)
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
library(sf)
#> Linking to GEOS 3.11.0, GDAL 3.5.3, PROJ 9.1.0; sf_use_s2() is TRUE
dat <- tibble(x = 1:5, y = 11:15)
dat
#> # A tibble: 5 × 2
#> x y
#> <int> <int>
#> 1 1 11
#> 2 2 12
#> 3 3 13
#> 4 4 14
#> 5 5 15
dat_sf <- st_sf(geometry=st_sfc())
dat_sf
#> Simple feature collection with 0 features and 0 fields
#> Bounding box: xmin: NA ymin: NA xmax: NA ymax: NA
#> CRS: NA
#> [1] geometry
#> <0 rows> (or 0-length row.names)
bind_rows(dat, dat_sf)
#> Error in `vec_rbind()`:
#> ! `c()` method returned a vector of unexpected size 6 instead of 5.
#> ℹ In file 'c.c' at line 414.
#> ℹ 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://tidyverse.org/help/>) and the full backtrace.
bind_rows(dat_sf, dat)
#> Error in `vec_rbind()`:
#> ! `c()` method returned a vector of unexpected size 6 instead of 5.
#> ℹ In file 'c.c' at line 414.
#> ℹ 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://tidyverse.org/help/>) and the full backtrace.
bind_rows(dat_sf, dat_sf)
#> Simple feature collection with 0 features and 0 fields
#> Bounding box: xmin: NA ymin: NA xmax: NA ymax: NA
#> CRS: NA
#> [1] geometry
#> <0 rows> (or 0-length row.names)
bind_rows(dat, dat)
#> # A tibble: 10 × 2
#> x y
#> <int> <int>
#> 1 1 11
#> 2 2 12
#> 3 3 13
#> 4 4 14
#> 5 5 15
#> 6 1 11
#> 7 2 12
#> 8 3 13
#> 9 4 14
#> 10 5 15 Created on 2024-05-02 with reprex v2.1.0 Session infosessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#> setting value
#> version R version 4.3.3 (2024-02-29)
#> os macOS Sonoma 14.3.1
#> system aarch64, darwin20
#> ui X11
#> language (EN)
#> collate en_US.UTF-8
#> ctype en_US.UTF-8
#> tz Australia/Brisbane
#> date 2024-05-02
#> pandoc 3.1.1 @ /Applications/RStudio.app/Contents/Resources/app/quarto/bin/tools/ (via rmarkdown)
#>
#> ─ Packages ───────────────────────────────────────────────────────────────────
#> package * version date (UTC) lib source
#> class 7.3-22 2023-05-03 [2] CRAN (R 4.3.3)
#> classInt 0.4-10 2023-09-05 [1] CRAN (R 4.3.0)
#> cli 3.6.2 2023-12-11 [1] CRAN (R 4.3.1)
#> DBI 1.2.2 2024-02-16 [1] CRAN (R 4.3.1)
#> digest 0.6.35 2024-03-11 [1] CRAN (R 4.3.1)
#> dplyr * 1.1.4 2023-11-17 [1] CRAN (R 4.3.1)
#> e1071 1.7-14 2023-12-06 [1] CRAN (R 4.3.1)
#> evaluate 0.23 2023-11-01 [1] CRAN (R 4.3.1)
#> fansi 1.0.6 2023-12-08 [1] CRAN (R 4.3.1)
#> fastmap 1.1.1 2023-02-24 [1] CRAN (R 4.3.0)
#> fs 1.6.3 2023-07-20 [1] CRAN (R 4.3.0)
#> generics 0.1.3 2022-07-05 [1] CRAN (R 4.3.0)
#> glue 1.7.0 2024-01-09 [1] CRAN (R 4.3.1)
#> htmltools 0.5.8.1 2024-04-04 [1] CRAN (R 4.3.1)
#> KernSmooth 2.23-22 2023-07-10 [2] CRAN (R 4.3.3)
#> knitr 1.45 2023-10-30 [1] CRAN (R 4.3.1)
#> lifecycle 1.0.4 2023-11-07 [1] CRAN (R 4.3.1)
#> magrittr 2.0.3 2022-03-30 [1] CRAN (R 4.3.0)
#> pillar 1.9.0 2023-03-22 [1] CRAN (R 4.3.0)
#> pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.3.0)
#> proxy 0.4-27 2022-06-09 [1] CRAN (R 4.3.0)
#> purrr 1.0.2 2023-08-10 [1] CRAN (R 4.3.0)
#> R.cache 0.16.0 2022-07-21 [2] CRAN (R 4.3.0)
#> R.methodsS3 1.8.2 2022-06-13 [2] CRAN (R 4.3.0)
#> R.oo 1.26.0 2024-01-24 [2] CRAN (R 4.3.1)
#> R.utils 2.12.3 2023-11-18 [2] CRAN (R 4.3.1)
#> R6 2.5.1 2021-08-19 [1] CRAN (R 4.3.0)
#> Rcpp 1.0.12 2024-01-09 [1] CRAN (R 4.3.1)
#> reprex 2.1.0 2024-01-11 [2] CRAN (R 4.3.1)
#> rlang 1.1.3 2024-01-10 [1] CRAN (R 4.3.1)
#> rmarkdown 2.26 2024-03-05 [1] CRAN (R 4.3.1)
#> rstudioapi 0.16.0 2024-03-24 [1] CRAN (R 4.3.1)
#> sessioninfo 1.2.2 2021-12-06 [2] CRAN (R 4.3.0)
#> sf * 1.0-16 2024-03-24 [1] CRAN (R 4.3.1)
#> styler 1.10.3 2024-04-07 [2] CRAN (R 4.3.1)
#> tibble * 3.2.1 2023-03-20 [1] CRAN (R 4.3.0)
#> tidyselect 1.2.1 2024-03-11 [1] CRAN (R 4.3.1)
#> units 0.8-5 2023-11-28 [1] CRAN (R 4.3.1)
#> utf8 1.2.4 2023-10-22 [1] CRAN (R 4.3.1)
#> vctrs 0.6.5 2023-12-01 [1] CRAN (R 4.3.1)
#> winch 0.1.1 2024-02-19 [1] CRAN (R 4.3.1)
#> withr 3.0.0 2024-01-16 [1] CRAN (R 4.3.1)
#> xfun 0.43 2024-03-25 [1] CRAN (R 4.3.1)
#> yaml 2.3.8 2023-12-11 [1] CRAN (R 4.3.1)
#>
#> [1] /Users/nick/Library/R/arm64/4.3/library
#> [2] /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library
#>
#> ────────────────────────────────────────────────────────────────────────────── |
I'm not sure if this is an error of the
vctrs
implementation insf
or a problem invtrcs
, as the suggestion is to report it here I'll do that first. The error occurs when0
rows are added to ansf
data.frame
(as part of code where the number of rows added is variable).Created on 2022-11-25 with reprex v2.0.2
The text was updated successfully, but these errors were encountered: