Skip to content
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

Error in vec_rbind() #1934

Open
DrewryWang opened this issue May 11, 2024 · 7 comments
Open

Error in vec_rbind() #1934

DrewryWang opened this issue May 11, 2024 · 7 comments
Labels
reprex needs a minimal reproducible example

Comments

@DrewryWang
Copy link

! c() method returned a vector of unexpected size 10002 instead of 10000.
ℹ In file c.c at line 414.
ℹ Install the winch package to get additional debugging info the next time you get this error.
ℹ 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:

  1. ├─sfnetworks::to_spatial_smooth(net)
  2. │ └─sfnetworks:::bind_rows_list(edges, new_edges)
  3. │ └─dplyr::bind_rows(ins)
  4. │ └─vctrs::vec_rbind(!!!dots, .names_to = .id, .error_call = current_env())
  5. └─rlang:::stop_internal_c_lib(...)
  6. └─rlang::abort(message, call = call, .internal = TRUE, .frame = frame)
@DrewryWang
Copy link
Author

After I created a sfnetwork object from linestrings, I was trying to smooth the network by removing pseudo nodes.
Here are my code:
Link_Output_sf <- Link_to_Linestring(Link_Output[1:10000,])
net <- sfnetworks::as_sfnetwork(Link_Output_sf)
smoothed_net = to_spatial_smooth(net)

you can find more info about sfnetworks and removing pseudo nodes at the link:
https://luukvdmeer.github.io/sfnetworks/articles/sfn02_preprocess_clean.html

@DavisVaughan
Copy link
Member

Could you please turn this into a self-contained reprex (short for minimal reproducible example)? It will help us help you if we can be sure we're all working with/looking at the same stuff.

If you've never heard of a reprex before, you might want to start by reading the tidyverse.org help page.

You can install reprex by running (you may already have it, though, if you have the tidyverse package installed):

install.packages("reprex")

Thanks

@DavisVaughan DavisVaughan added the reprex needs a minimal reproducible example label May 14, 2024
@DrewryWang
Copy link
Author

@DavisVaughan Sorry that I couldn't turn it into a reprex as the code needs to read a external shp file.
However, I am attaching the minimal code and the file necessary as below. Hopefully you can run it on your side.

##Code
library(sfnetworks)
library(sf)
Link_Output_sf <- read_sf('~/link_output.shp') # Replace the shp file within the attached folder after unzip
net <- sfnetworks::as_sfnetwork(Link_Output_sf)
smoothed_net = to_spatial_smooth(net)
##End of Code

link_output_shp.zip

@guglicap
Copy link

guglicap commented Sep 9, 2024

@DrewryWang have you managed to work around this somehow?

@freyja-bt
Copy link

Ran into this same error.
I tried @DrewryWang's code and i'm getting the same "line 412" error as below instead of the line 414 error mentioned in the original post.

problem arises when there is an sf object in a list with empty data frames and bind_rows is called. problem does not arise if an sf object is in a list with non-empty data frames or if a non-sf data frame is in a list with empty data frames.

library(dplyr);library(sf)
#> 
#> 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
#> Linking to GEOS 3.12.1, GDAL 3.8.4, PROJ 9.3.1; sf_use_s2() is TRUE
bind_rows(list(db1 = data.frame(), db2=data.frame(x=84, y=32)%>%st_as_sf(coords=c("x","y"))))
#> 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://tidyverse.org/help/>) and the full backtrace.

Created on 2024-09-09 with reprex v2.1.1

@zenfey
Copy link

zenfey commented Oct 17, 2024

Ran into this same error. I tried @DrewryWang's code and i'm getting the same "line 412" error as below instead of the line 414 error mentioned in the original post.

problem arises when there is an sf object in a list with empty data frames and bind_rows is called. problem does not arise if an sf object is in a list with non-empty data frames or if a non-sf data frame is in a list with empty data frames.

library(dplyr);library(sf)
#> 
#> 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
#> Linking to GEOS 3.12.1, GDAL 3.8.4, PROJ 9.3.1; sf_use_s2() is TRUE
bind_rows(list(db1 = data.frame(), db2=data.frame(x=84, y=32)%>%st_as_sf(coords=c("x","y"))))
#> 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://tidyverse.org/help/>) and the full backtrace.

Created on 2024-09-09 with reprex v2.1.1

I came into same issue when list contains empty empty with zero rows. One fix is to filter out empty dataframes before calling bind_rows.

@krlmlr krlmlr changed the title Error in `vec_rbind() Error in vec_rbind() Oct 23, 2024
@MalditoBarbudo
Copy link

I run into this issue also. A very simple reprex:

library(sf)
#> Linking to GEOS 3.12.2, GDAL 3.9.2, PROJ 9.5.0; sf_use_s2() is TRUE
library(dplyr)
#> 
#> Adjuntando el paquete: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
g <-  sf::st_sfc(st_point(1:2))
foo <- sf::st_sf(a = 3, g) |>
  dplyr::as_tibble()
bar <- dplyr::tibble()
dplyr::bind_rows(foo, bar)
#> 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://tidyverse.org/help/>) and the full backtrace.

Created on 2024-10-29 with reprex v2.1.0

If I remove the geometry column or transform it to any other class, it works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
reprex needs a minimal reproducible example
Projects
None yet
Development

No branches or pull requests

6 participants