vctrs icon indicating copy to clipboard operation
vctrs copied to clipboard

"stability" vignette's note on `c.factor()` is not longer accurate

Open jmbarbone opened this issue 2 years ago • 0 comments

?factor

Since R 4.1.0, when using c to combine a (possibly ordered) factor with other objects, if all objects are (possibly ordered) factors, the result will be a factor with levels the union of the level sets of the elements, in the order the levels occur in the level sets of the elements (which means that if all the elements have the same level set, that is the level set of the result), equivalent to how unlist operates on a list of factor objects.

The example in the stability vignette is now confusing:

image

library(vctrs)

fa <- factor("a")
fb <- factor("b")

c(fa, fb)
#> [1] a b
#> Levels: a b
vec_c(fa, fb)
#> [1] a b
#> Levels: a b
c(fb, fa)
#> [1] b a
#> Levels: b a
vec_c(fb, fa)
#> [1] b a
#> Levels: b a

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

jmbarbone avatar Nov 05 '22 20:11 jmbarbone