Open DrewryWang opened 6 months ago
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
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 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.
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)
@DrewryWang have you managed to work around this somehow?
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
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 andbind_rows
is called. problem does not arise if ansf
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.
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.
!
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: ▆