Bug 16137 - NaN is serialized as NA in ASCII format
Summary: NaN is serialized as NA in ASCII format
Status: CLOSED FIXED
Alias: None
Product: R
Classification: Unclassified
Component: I/O (show other bugs)
Version: R-devel (trunk)
Hardware: Other Linux
: P5 normal
Assignee: R-core
URL:
Depends on:
Blocks:
 
Reported: 2015-01-06 18:36 UTC by Alexey Stukalov
Modified: 2015-12-14 13:47 UTC (History)
2 users (show)

See Also:


Attachments
Fix NaN/NA serializing/deserializing. (1.07 KB, patch)
2015-01-06 18:36 UTC, Alexey Stukalov
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Alexey Stukalov 2015-01-06 18:36:33 UTC
Created attachment 1715 [details]
Fix NaN/NA serializing/deserializing.

When saving in ASCII format, both NA and NaN real values are serialized as NA. This looks to be a rather old R issue. 

Trivial example:

> x = c( 1.0, NA, NaN )
> save( x, file = "na_test.RData", ascii = TRUE )
> load( file = "na_test.RData" )
> x
[1]  1 NA NA

Attached is the patch that serializes NA as "NA" and NaN as "NaN" and adds "NaN" deserialization. However, files saved with this patch should be backward-compatible with the unpatched R versions as "NaN" is recognized by sscanf(buf, "%lg", &d).
Comment 1 Martin Maechler 2015-01-08 11:18:58 UTC
Thank you for the careful concise example and quality patch!!

I'm commiting the fix for this to both  R-devel (to be 3.2.0) and R-patched (3.1.2 patched).
Comment 2 Alexey Stukalov 2015-01-08 12:03:28 UTC
Thanks!