Skip to content

Too large integer values result in warning and NA #151

@djvanderlaan

Description

@djvanderlaan

Values larger than .Machine$integer.max or smaller than -.Machine$integer.max result in a warning and a missing value (djvanderlaan/datapackage#23):

> yaml.load("foo: 9876543219")
$foo
[1] NA

Warning message:
In yaml.load("foo: 9876543219") :
  NAs introduced by coercion: 9876543219 is out of integer range

Probably better would be to convert to double in such cases. Doubles can handle without loss of precision values up to 2^52 (or 53; can't remember); or use int64 introducing a dependency on bit64.

A current workaround for me is:

yaml.load("foo: 9876543219", handlers=list(int=function(x) {
  x <- as.numeric(x); 
  if (x <= .Machine$integer.max & x >= .Machine$integer.max) as.integer(x) else x
}))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions