romainfrancois commented on a change in pull request #10730: URL: https://github.com/apache/arrow/pull/10730#discussion_r672174111
########## File path: r/src/array_to_vector.cpp ########## @@ -69,13 +69,25 @@ class Converter { // special case when there is only one array if (chunked_array_->num_chunks() == 1) { const auto& array = chunked_array_->chunk(0); - if (arrow::r::GetBoolOption("arrow.use_altrep", true) && array->length() > 0 && - array->null_count() == 0) { + // using altrep if + // - the arrow.use_altrep is set to TRUE or unset + // - the array has at least one element + // - either it has no nulls or the data is mutable + if (arrow::r::GetBoolOption("arrow.use_altrep", true) && array->length() > 0) { switch (array->type()->id()) { case arrow::Type::DOUBLE: - return arrow::r::MakeDoubleArrayNoNull(array); + if (array->null_count() == 0 || array->data()->buffers[1]->is_mutable()) { Review comment: One consequence is that we can't use altrep when taking slices of an Array as the buffer is at least held by two Arrays then. ``` r library(arrow, warn.conflicts = FALSE) #> See arrow_info() for available features is_altrep <- arrow:::is_altrep v_int <- Array$create(c(1L, NA, 3L)) is_altrep(v_int$as_vector()) #> [1] TRUE is_altrep(as.vector(v_int$Slice(1))) #> [1] FALSE ``` <sup>Created on 2021-07-19 by the [reprex package](https://reprex.tidyverse.org) (v2.0.0)</sup> I commented out the relevant tests in `test-altrep.R`. Does this matter given that the data there is irrelevant because it's identified as null ? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: github-unsubscr...@arrow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org