diff --git a/.travis.yml b/.travis.yml index 74b5bad7fe7..36a2dccf666 100644 --- a/.travis.yml +++ b/.travis.yml @@ -362,6 +362,7 @@ matrix: - $TRAVIS_BUILD_DIR/ci/travis_before_script_cpp.sh --only-library - export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$TRAVIS_BUILD_DIR/cpp-install/lib - export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:$TRAVIS_BUILD_DIR/cpp-install/lib/pkgconfig + - export CXX11FLAGS=-Wall - pushd ${TRAVIS_BUILD_DIR}/r after_success: - Rscript ../ci/travis_upload_r_coverage.R diff --git a/r/src/array_from_vector.cpp b/r/src/array_from_vector.cpp index 0c21e94e277..0d4e31883f0 100644 --- a/r/src/array_from_vector.cpp +++ b/r/src/array_from_vector.cpp @@ -763,6 +763,13 @@ std::shared_ptr GetFactorType(SEXP factor) { std::shared_ptr InferType(SEXP x) { switch (TYPEOF(x)) { + case ENVSXP: + if (Rf_inherits(x, "arrow::Array")) { + Rcpp::ConstReferenceSmartPtrInputParameter> array( + x); + return static_cast>(array)->type(); + } + break; case LGLSXP: return boolean(); case INTSXP: @@ -915,6 +922,11 @@ bool CheckCompatibleFactor(SEXP obj, const std::shared_ptr& typ std::shared_ptr Array__from_vector( SEXP x, const std::shared_ptr& type, bool type_infered) { + // short circuit if `x` is already an Array + if (Rf_inherits(x, "arrow::Array")) { + return Rcpp::ConstReferenceSmartPtrInputParameter>(x); + } + // special case when we can just use the data from the R vector // directly. This still needs to handle the null bitmap if (arrow::r::can_reuse_memory(x, type)) { diff --git a/r/tests/testthat/test-Array.R b/r/tests/testthat/test-Array.R index 68fd9dc04be..fd2fe518631 100644 --- a/r/tests/testthat/test-Array.R +++ b/r/tests/testthat/test-Array.R @@ -410,3 +410,8 @@ test_that("Array$as_vector() converts to integer (ARROW-3794)", { expect_equal(a$type, uint8()) expect_equal(a$as_vector(), 0:255) }) + +test_that("array() recognise arrow::Array (ARROW-3815)", { + a <- array(1:10) + expect_equal(a, array(a)) +}) diff --git a/r/tests/testthat/test-RecordBatch.R b/r/tests/testthat/test-RecordBatch.R index c0295bac2c8..a492f0f088f 100644 --- a/r/tests/testthat/test-RecordBatch.R +++ b/r/tests/testthat/test-RecordBatch.R @@ -145,3 +145,8 @@ test_that("RecordBatch dim() and nrow() (ARROW-3816)", { expect_equal(dim(batch), c(10L, 2L)) expect_equal(nrow(batch), 10L) }) + +test_that("record_batch() handles arrow::Array", { + batch <- record_batch(x = 1:10, y = arrow::array(1:10)) + expect_equal(batch$schema, schema(x = int32(), y = int32())) +}) diff --git a/r/tests/testthat/test-chunkedarray.R b/r/tests/testthat/test-chunkedarray.R index 5e22e5cf31e..9505b8f22a0 100644 --- a/r/tests/testthat/test-chunkedarray.R +++ b/r/tests/testthat/test-chunkedarray.R @@ -265,3 +265,10 @@ test_that("chunked_array() handles 0 chunks if given a type", { expect_equal(a$length(), 0L) } }) + +test_that("chunked_array() can ingest arrays (ARROW-3815)", { + expect_equal( + chunked_array(1:5, array(6:10))$as_vector(), + 1:10 + ) +})