rmongodb
rmongodb copied to clipboard
NA written as NULL and read back as NULL
In a recent version NA values were set to write as NULL (see #44). This seem problematic to me.
when you read the data back bson NULL is converted back to R NULL which means you cannot use mongo.find.all with data.frame=TRUE because you cannot have NULL in your data.frame (length zero). Is there not a more proper bson NA? What was wrong with nan?
NaN - standing for not a number, is a numeric data type. And it is numeric type in mongodb too... The nearest analogue R's NA_*
family is mongodb's null
.
I think we can to try to convert mongodb's null
to R's NA
(add option like null_to_NA = TRUE
). What do you think?
That would work for me. I think it is the only way if we have 3 options in R (null/NA/NaN) but only 2 in mongo.
I guess null_to_NA has to default to FALSE but I guess it could make sense to set it to TRUE if data.frame=TRUE or throw a warning.
A flag to convert NULL to NA would be nice, I've run into this issue where values that were NA in R were written as NULL in mongo, and read back in as NULL in R. As mentioned above, this causes data.frame=TRUE to fail.