Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistencies with NA and other types of 'missingness' #41

Open
ateucher opened this issue Feb 3, 2018 · 2 comments
Open

Inconsistencies with NA and other types of 'missingness' #41

ateucher opened this issue Feb 3, 2018 · 2 comments

Comments

@ateucher
Copy link

ateucher commented Feb 3, 2018

I noticed that different classes of NA were treated differently on a round trip:

library(V8)
ct <- v8()

## Logical and character of length one return as NULL
ct$assign("na", NA)
ct$get("na")
#> NULL

ct$assign("na_char", NA_character_)
ct$get("na_char")
#> NULL

## Real, integer, and complex return as "NA" string
ct$assign("na_real", NA_real_)
ct$get("na_real")
#> [1] "NA"

ct$assign("na_int", NA_integer_)
ct$get("na_int")
#> [1] "NA"

ct$assign("na_complex", NA_complex_)
ct$get("na_complex")
#> [1] "NA"

## When vector is greater than length 1, get vector of NAs back:
ct$assign("nas", c(NA, NA))
ct$get("nas")
#> [1] NA NA

I then looked at other 'missing' types: NaN and NULL:

## NaN returns as "NaN" string
ct$assign("nan", NaN)
ct$get("nan")
#> [1] "NaN"

## NULL returns as an empty list()
ct$assign("null_", NULL)
ct$get("null_")
#> named list()

I think the inconsistencies in the NA types is a bit of a problem, but not sure what you think about the NaN and NULL situations?

@ateucher ateucher changed the title Inconsistencies with NA and different types of 'missingness' Inconsistencies with NA and other types of 'missingness' Feb 3, 2018
@jeroen
Copy link
Owner

jeroen commented Feb 6, 2019

Yeah the problem is that we currently use json to serialize the data, which does not support NA types. Maybe with the new V8 we can try a binary serialization format.

@ateucher
Copy link
Author

ateucher commented Feb 12, 2019

Yup, that makes sense for the NaN vs NULL vs NA cases... but I'm still surprised at the differences between NA_character_ and NA_real_ (for example), where the former is comes back as NULL, and the latter comes back as "NA" character string...

EDIT: Actually, this is perhaps better discussed in jsonlite:

# length one
jsonlite::toJSON(NA_character_)
#> [null]
jsonlite::toJSON(NA_real_)
#> ["NA"]

# greater than length one
jsonlite::toJSON(rep(NA_character_, 2))
#> [null,null]
jsonlite::toJSON(rep(NA_real_, 2))
#> ["NA","NA"]

# And coming back the other way:
jsonlite::fromJSON('null')
#> NULL
jsonlite::fromJSON('"NA"')
#> [1] "NA"

jsonlite::fromJSON('[null,null]')
#> [1] NA NA
jsonlite::fromJSON('["NA","NA"]')
#> [1] NA NA

Created on 2019-02-12 by the reprex package (v0.2.1)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants