Skip to content

fct_recode removes label attribute #346

@iagogv3

Description

@iagogv3

Hi!

fct_recode removes label attribute (and seems that it removes all the attributes). I expect it would not do (it may have sense that it removes a labels attribute, but not others).

Reprex:

library(haven)
library(forcats)
path <- system.file("examples", "iris.dta", package = "haven")
read_dta(path) |> str()
...
...
...
$ species    : chr [1:150] "setosa" "setosa" "setosa" "setosa" ...
  ..- attr(*, "label")= chr "Species"
  ..- attr(*, "format.stata")= chr "%10s"
# However
read_dta(path)$species |> fct_recode(seto = "setosa") |> str()
 Factor w/ 3 levels "seto","versicolor",..: 1 1 1 1 1 1 1 1 1 1 ...

Metadata

Metadata

Assignees

No one assigned

    Labels

    reprexneeds a minimal reproducible example

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions