now interprets empty variables with empty levels attribute as logicals to avoid returning factors with empty levels

This commit is contained in:
Andreas Gammelgaard Damsbo 2025-02-25 10:36:37 +01:00
commit 7dfbb9b549
No known key found for this signature in database
3 changed files with 31 additions and 5 deletions

View file

@ -63,6 +63,8 @@ ta loss in case of rich formatted and labelled data.
\details{
Please refer to parent functions for extended documentation.
To avoid redundancy calls and errors, functions are copy-pasted here
Empty variables with empty levels attribute are interpreted as logicals
}
\examples{
# will preserve all attributes
@ -77,5 +79,12 @@ structure(c(1, 2, 3, 2, 10, 9),
labels = c(Unknown = 9, Refused = 10),
class = "haven_labelled"
) |>
as_factor()
as_factor() |> class()
structure(rep(NA,10),
class = c("labelled")
) |>
as_factor() |> summary()
rep(NA,10) |> as_factor()
}