Skip to content

[R] Reconsider behavior of as.<type>.ArrowDatum functions #28097

@asfimport

Description

@asfimport

As discussed at #9942 (comment) the as.double(), as.integer(), and as.character() methods for ArrowDatum return R vectors of the specified R types, whereas in dplyr, these same functions perform casts to the analogous Arrow types 

Compare the definitions:

  • ArrowDatum methods:

    arrow/r/R/arrow-datum.R

    Lines 139 to 145 in ace2bfc

    as.double.ArrowDatum <- function(x, ...) as.double(as.vector(x), ...)
    #' @export
    as.integer.ArrowDatum <- function(x, ...) as.integer(as.vector(x), ...)
    #' @export
    as.character.ArrowDatum <- function(x, ...) as.character(as.vector(x), ...)

  • dplyr functions:

    arrow/r/R/dplyr.R

    Lines 399 to 432 in f2db785

    as.character = function(x) {
    FUN("cast", x, options = cast_options(to_type = string()))
    },
    as.double = function(x) {
    FUN("cast", x, options = cast_options(to_type = float64()))
    },
    as.integer = function(x) {
    FUN(
    "cast",
    x,
    options = cast_options(
    to_type = int32(),
    allow_float_truncate = TRUE,
    allow_decimal_truncate = TRUE
    )
    )
    },
    as.integer64 = function(x) {
    FUN(
    "cast",
    x,
    options = cast_options(
    to_type = int64(),
    allow_float_truncate = TRUE,
    allow_decimal_truncate = TRUE
    )
    )
    },
    as.logical = function(x) {
    FUN("cast", x, options = cast_options(to_type = boolean()))
    },
    as.numeric = function(x) {
    FUN("cast", x, options = cast_options(to_type = float64()))
    },

    Consider whether the ArrowDatum methods should instead perform casts but keep the data in Arrow so that the user would have to also call as.vector() to return the data as an R vector.

Reporter: Ian Cook / @ianmcook
Assignee: Ian Cook / @ianmcook

Related issues:

Note: This issue was originally created as ARROW-12292. Please see the migration documentation for further details.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions