Skip to content

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

@jmbarbone

Description

@jmbarbone

?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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions