diff --git a/r/NAMESPACE b/r/NAMESPACE index ef32160a6..c76f380ec 100644 --- a/r/NAMESPACE +++ b/r/NAMESPACE @@ -65,7 +65,6 @@ S3method(c,nanoarrow_vctr) S3method(convert_array,default) S3method(convert_array,double) S3method(convert_array,factor) -S3method(convert_array,matrix) S3method(convert_array,nanoarrow_vctr) S3method(convert_array,vctrs_partial_frame) S3method(convert_array_extension,default) diff --git a/r/R/convert-array.R b/r/R/convert-array.R index 41d90e3aa..a33273e70 100644 --- a/r/R/convert-array.R +++ b/r/R/convert-array.R @@ -173,37 +173,6 @@ convert_array.double <- function(array, to, ...) { } } -#' @export -convert_array.matrix <- function(array, to, ...) { - schema <- infer_nanoarrow_schema(array) - parsed <- nanoarrow_schema_parse(schema) - if (parsed$type != "fixed_size_list") { - stop_cant_convert_array(array, to) - } - - if (identical(to, matrix())) { - to <- matrix( - infer_nanoarrow_ptype(array$children[[1]]), - nrow = 0, - ncol = parsed$fixed_size - ) - } - - if (ncol(to) != parsed$fixed_size) { - stop( - sprintf( - "Can't convert fixed_size_list(list_size=%d) to matrix with %d cols", - parsed$fixed_size, - ncol(to) - ) - ) - } - - attributes(to) <- NULL - child_vctr <- convert_array(array$children[[1]], to) - matrix(child_vctr, ncol = parsed$fixed_size, byrow = TRUE) -} - #' @export convert_array.vctrs_partial_frame <- function(array, to, ...) { ptype <- infer_nanoarrow_ptype(array) diff --git a/r/src/materialize.c b/r/src/materialize.c index 94cd9a31b..0ece9c3f3 100644 --- a/r/src/materialize.c +++ b/r/src/materialize.c @@ -622,6 +622,12 @@ static int nanoarrow_materialize_matrix(struct RConverter* converter, return EINVAL; } + if (converter->schema_view.fixed_size != Rf_ncols(converter->ptype_view.ptype)) { + Rf_error("Can't convert fixed_size_list(list_size=%d) to matrix with %d cols", + (int)converter->schema_view.fixed_size, + Rf_ncols(converter->ptype_view.ptype)); + } + int64_t raw_src_offset = src->array_view->array->offset + src->offset; int64_t list_length = src->array_view->layout.child_size_elements; int64_t offset; diff --git a/r/tests/testthat/test-convert-array.R b/r/tests/testthat/test-convert-array.R index ea39f4df7..e6a18f850 100644 --- a/r/tests/testthat/test-convert-array.R +++ b/r/tests/testthat/test-convert-array.R @@ -1045,7 +1045,6 @@ test_that("convert to vector works for fixed_size_list_of() -> matrix()", { mat <- matrix(1:6, ncol = 2, byrow = TRUE) array <- as_nanoarrow_array(mat) - expect_identical(convert_array(array, matrix()), mat) expect_identical( convert_array(array, matrix(double(), ncol = 2)), matrix(as.double(1:6), ncol = 2, byrow = TRUE)