larmarange / labelled

Manipulating labelled vectors in R
https://larmarange.github.io/labelled/
GNU General Public License v3.0
75 stars 16 forks source link

Unexpected behaviour when using user_na_to_tagged_na() #114

Closed rps13 closed 2 years ago

rps13 commented 2 years ago

When using user_na_to_tagged_na() and specifying two missing values as so:

test <- rep(c(-99, -99, 3, 5, -1), 120)
labelled::na_values(test) <- c(-99, -1)

After using user_na_to_tagged_na(), I get the warning:

Warning message:
In remove_user_na.haven_labelled_spss(x, user_na_to_tagged_na = TRUE) :
  360 different user-defined missing values found in 'x'.
A maximum of 26 could be tagged.

Looking through the code, it seems that remove_user_na.haven_labelled_spss() checks the length of the vector containing missing values using val_to_tag <- x[is.na(x) & !is.na(unclass(x))] %>% unclass() rather than the length of the vector of the unique values (in the example -1 and -99 appear 360 times in the vector test)?

larmarange commented 2 years ago

Thanks @rps13 for having identified the bug

Should be fixed in #115

rps13 commented 2 years ago

@larmarange Thanks! I just re-built the package from branch "issue_114" with devtools::install_github and it works fine for me.