Closed chengchou closed 4 years ago
hi @chengchou Here's some background on why labelled missing values don't work for integers. I haven't checked your code yet, but I would name the argument something like coerce_integer_to_double
and I would have to add tests that integers without labelled missing values don't get coerced.
I don't consider it very urgent though, as people could simply convert integers beforehand. Have you ever sent a pull request?
@rubenarslan "tests that integers without labelled missing values don't get coerced" is a good point. coerce_integer_to_double
is self-explaining---good name. No I haven't sent a pull request before.
@rubenarslan Sorry, where does detect_missing
locate with R directory?
I was trying to use
detect_missing
to clean the missing data in a dataset, of which a few columns are integers.detect_missing
cannot correctly label the missing values.Consider the following dataset
rd1
:The only difference between
x1
andx2
is thatx1
has only integers. Applyingdetect_missing
will only affectx2
, but996
inx1
remains unchanged.I looked into the codes of
detect_missing
and found that the problem was that the functionhaven::tagged_na
does not work with vectors of integers. So you include the conditionis.double
in a fewif
statements.If I modified these these lines (below) by removing the check for
is.double
,detect_missing
will work for columns of integers by converting these columns of integers to column of double. I understand that convertinginteger
todouble
could cause problems later, but it might not be a bad idea to add an option of letting users allow for the conversion so that missing values can be labelled correctly for integer columns.detect_missing2
function below is a simple modification of the currentdetect_missing
by adding an extra optionforce_integer = TRUE
orFALSE
. (The changes are highlighted.) Whenforce_integer = TRUE
, the integer columns will be converted to double and missing values will be labelled.