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

Write NA as string #780

Merged
merged 1 commit into from
Sep 9, 2021
Merged

Conversation

renkun-ken
Copy link
Member

What problem did you solve?

Closes #776

Since JSON does not support NA, NaN, Inf values, they can only be written as strings in the following way:

jsonlite::write_json(x, file, na = "string", null = "null", auto_unbox = TRUE)

One remaining issue is that these values will not work properly when filtering is used in the data viewer, i.e. if one filters a column by "Greater than 0", Inf is not regarded as Inf > 0 but ignored.

(If you have)Screenshot

image

How can I check this pull request?

The following code should open a data viewer where Inf and NA values are correctly displayed in the data grid.

dt <- data.frame(
  id = 1:6,
  x = c(1, 2, NA, 3, Inf, -Inf),
  y = c("A", "B", NA, NA, NA, "D")
)

View(dt)

Copy link
Collaborator

@ElianHugh ElianHugh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! In the future we could probably look at comparators for sorting the values properly

@renkun-ken
Copy link
Member Author

It looks like JavaScript has support for NaN and infinite values but JSON has no way to represent them. We are only using jsonlite to write the structure to be inserted as part of the HTML, not really reading it as json anyway. In the future, we might have a better way to simply produce the correct JavaScript object directly.

@renkun-ken renkun-ken merged commit 4d6a663 into REditorSupport:master Sep 9, 2021
ElianHugh pushed a commit to ElianHugh/vscode-R that referenced this pull request May 12, 2022
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

Successfully merging this pull request may close these issues.

Inf is unable to be displayed in the vscode-r table window
2 participants