-
Notifications
You must be signed in to change notification settings - Fork 299
Closed
Labels
bugan unexpected problem or unintended behavioran unexpected problem or unintended behavior
Description
sf objects seem to have their own version of "character" ('character' chr rather than chr).
Depending on how one extracts a column, the 'character' chr stays in and it can create issues with other R functions.
At least it does so with vctrs and thus dplyr as shown below.
I did not check if drop is a generic which a sf method could fine tune, or if it could create issues beyond vctrs.
Strangely base R seems to interpret 'character' chr as a genuine chr.
library(sf)
#> Linking to GEOS 3.14.1, GDAL 3.11.5, PROJ 9.6.2; sf_use_s2() is TRUE
library(dplyr, warn.conflicts = FALSE)
pt1 = st_point(c(0,1))
pt2 = st_point(c(1,1))
d = data.frame(a = letters[1:2])
d$geom = st_sfc(pt1, pt2)
df = st_as_sf(d)
str(df[["a"]]) # same as str(st_drop_geometry(df)[, "a"])
#> chr [1:2] "a" "b"
str(df[, "a", drop = TRUE])
#> 'character' chr [1:2] "a" "b"
class(df[["a"]])
#> [1] "character"
class(df[, "a", drop = TRUE])
#> [1] "character"
is.character(df[["a"]])
#> [1] TRUE
is.character(df[, "a", drop = TRUE])
#> [1] TRUE
full_join(data.frame(foo = df[["a"]]),
data.frame(foo = df[["a"]]))
#> Joining with `by = join_by(foo)`
#> foo
#> 1 a
#> 2 b
full_join(data.frame(foo = df[, "a", drop = TRUE]),
data.frame(foo = df[["a"]]))
#> Joining with `by = join_by(foo)`
#> Error in `stop_native_implementation()`:
#> ! `vec_ptype2.character.character()` is implemented at C level.
#> This R function is purely indicative and should never be called.
#> ℹ 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.
sessionInfo()
#> R version 4.5.2 (2025-10-31)
#> Platform: x86_64-redhat-linux-gnu
#> Running under: Fedora Linux 43 (KDE Plasma Desktop Edition)
#>
#> Matrix products: default
#> BLAS/LAPACK: FlexiBLAS OPENBLAS-OPENMP; LAPACK version 3.12.1
#>
#> locale:
#> [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
#> [3] LC_TIME=en_GB.UTF-8 LC_COLLATE=en_US.UTF-8
#> [5] LC_MONETARY=en_GB.UTF-8 LC_MESSAGES=en_US.UTF-8
#> [7] LC_PAPER=en_GB.UTF-8 LC_NAME=C
#> [9] LC_ADDRESS=C LC_TELEPHONE=C
#> [11] LC_MEASUREMENT=en_GB.UTF-8 LC_IDENTIFICATION=C
#>
#> time zone: Europe/Berlin
#> tzcode source: system (glibc)
#>
#> attached base packages:
#> [1] stats graphics grDevices utils datasets methods base
#>
#> other attached packages:
#> [1] dplyr_1.1.4 sf_1.0-23
#>
#> loaded via a namespace (and not attached):
#> [1] vctrs_0.6.5 cli_3.6.5 knitr_1.50 rlang_1.1.6
#> [5] xfun_0.54 DBI_1.2.3 KernSmooth_2.23-26 generics_0.1.4
#> [9] glue_1.8.0 htmltools_0.5.8.1 e1071_1.7-16 rmarkdown_2.30
#> [13] grid_4.5.2 tibble_3.3.0 evaluate_1.0.5 classInt_0.4-11
#> [17] fastmap_1.2.0 yaml_2.3.10 lifecycle_1.0.4 compiler_4.5.2
#> [21] fs_1.6.6 pkgconfig_2.0.3 Rcpp_1.1.0 rstudioapi_0.17.1
#> [25] digest_0.6.39 R6_2.6.1 tidyselect_1.2.1 class_7.3-23
#> [29] reprex_2.1.1 pillar_1.11.1 magrittr_2.0.4 tools_4.5.2
#> [33] withr_3.0.2 proxy_0.4-27 units_1.0-0Created on 2025-11-29 with reprex v2.1.1
Metadata
Metadata
Assignees
Labels
bugan unexpected problem or unintended behavioran unexpected problem or unintended behavior