Skip to content

as.integer64 is inconsistent in handling out-of-range string inputs #175

@MichaelChirico

Description

@MichaelChirico
as.integer64(c('9223372036854775809', '-9223372036854775809'))
# integer64
# [1] 9223372036854775807 <NA>

IINM, what's happening is that strtoll(), when encountering an out-of-range input, returns the end-of-range values, but for negative numbers, that's masked by NA_integer64_.

Here's how as.integer() behaves for reference:

as.integer(c('-2147483648', '-2147483647', '2147483647', '2147483648'))
# [1]          NA -2147483647  2147483647          NA
# Warning message:
# NAs introduced by coercion to integer range

I don't see this behavior described/explained in ?as.integer64.character.

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