diff --git a/r/NAMESPACE b/r/NAMESPACE index f91fe20ccaa..aa487cf60ac 100644 --- a/r/NAMESPACE +++ b/r/NAMESPACE @@ -96,6 +96,7 @@ S3method(tail,RecordBatchReader) S3method(tail,Scanner) S3method(tail,arrow_dplyr_query) S3method(type,ArrowDatum) +S3method(type,Expression) S3method(type,default) S3method(unique,ArrowDatum) S3method(vec_ptype_abbr,arrow_fixed_size_binary) diff --git a/r/R/type.R b/r/R/type.R index c84f1c18fbc..f8b408e4065 100644 --- a/r/R/type.R +++ b/r/R/type.R @@ -77,6 +77,9 @@ type.default <- function(x) Array__infer_type(x) #' @export type.ArrowDatum <- function(x) x$type +#' @export +type.Expression <- function(x) x$type + #----- metadata #' @title class arrow::FixedWidthType diff --git a/r/tests/testthat/test-type.R b/r/tests/testthat/test-type.R index b9613d651a9..168cdcff690 100644 --- a/r/tests/testthat/test-type.R +++ b/r/tests/testthat/test-type.R @@ -229,3 +229,13 @@ test_that("Type strings are correctly canonicalized", { "Unrecognized" ) }) + +test_that("type() gets the right type for Expression", { + x <- Expression$scalar(32L) + y <- Expression$scalar(10) + add_xy <- Expression$create("add", x, y) + + expect_equal(x$type, type(x)) + expect_equal(y$type, type(y)) + expect_equal(add_xy$type, type(add_xy)) +})