Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions r/src/array_from_vector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,13 @@ std::shared_ptr<arrow::DataType> GetFactorType(SEXP factor) {

std::shared_ptr<arrow::DataType> InferType(SEXP x) {
switch (TYPEOF(x)) {
case ENVSXP:
if (Rf_inherits(x, "arrow::Array")) {
Rcpp::ConstReferenceSmartPtrInputParameter<std::shared_ptr<arrow::Array>> array(
x);
return static_cast<std::shared_ptr<arrow::Array>>(array)->type();
}
break;
case LGLSXP:
return boolean();
case INTSXP:
Expand Down Expand Up @@ -915,6 +922,11 @@ bool CheckCompatibleFactor(SEXP obj, const std::shared_ptr<arrow::DataType>& typ

std::shared_ptr<arrow::Array> Array__from_vector(
SEXP x, const std::shared_ptr<arrow::DataType>& type, bool type_infered) {
// short circuit if `x` is already an Array
if (Rf_inherits(x, "arrow::Array")) {
return Rcpp::ConstReferenceSmartPtrInputParameter<std::shared_ptr<arrow::Array>>(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)) {
Expand Down
5 changes: 5 additions & 0 deletions r/tests/testthat/test-Array.R
Original file line number Diff line number Diff line change
Expand Up @@ -410,3 +410,8 @@ test_that("Array<int8>$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))
})
5 changes: 5 additions & 0 deletions r/tests/testthat/test-RecordBatch.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
})
7 changes: 7 additions & 0 deletions r/tests/testthat/test-chunkedarray.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
})