rmongodb icon indicating copy to clipboard operation
rmongodb copied to clipboard

NA written as NULL and read back as NULL

Open stanstrup opened this issue 9 years ago • 3 comments

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?

stanstrup avatar Mar 17 '15 13:03 stanstrup

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?

dselivanov avatar Apr 02 '15 11:04 dselivanov

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.

stanstrup avatar Apr 02 '15 12:04 stanstrup

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.

ericwatt avatar Jul 28 '15 14:07 ericwatt