diff --git a/r/R/feather.R b/r/R/feather.R index 5aaf340c6db..f8f3cb39354 100644 --- a/r/R/feather.R +++ b/r/R/feather.R @@ -147,14 +147,17 @@ read_feather <- function(file, col_select = NULL, as_data_frame = TRUE, ...) { file <- make_readable_file(file) on.exit(file$close()) } - reader <- FeatherReader$create(file, ...) + reader <- FeatherReader$create(file) col_select <- enquo(col_select) columns <- if (!quo_is_null(col_select)) { vars_select(names(reader), !!col_select) } - out <- reader$Read(columns) + out <- tryCatch( + reader$Read(columns), + error = function(e) { read_compressed_error(e) } + ) if (isTRUE(as_data_frame)) { out <- as.data.frame(out) diff --git a/r/R/parquet.R b/r/R/parquet.R index 45751b16170..689324113c2 100644 --- a/r/R/parquet.R +++ b/r/R/parquet.R @@ -52,10 +52,16 @@ read_parquet <- function(file, schema <- reader$GetSchema() names <- names(schema) indices <- match(vars_select(names, !!col_select), names) - 1L - tab <- reader$ReadTable(indices) + tab <- tryCatch( + reader$ReadTable(indices), + error = function(e) { read_compressed_error(e) } + ) } else { # read all columns - tab <- reader$ReadTable() + tab <- tryCatch( + reader$ReadTable(), + error = function(e) { read_compressed_error(e) } + ) } if (as_data_frame) { diff --git a/r/R/util.R b/r/R/util.R index 3362c0f4fda..97932cbaf0a 100644 --- a/r/R/util.R +++ b/r/R/util.R @@ -45,3 +45,16 @@ is_list_of <- function(object, class) { } empty_named_list <- function() structure(list(), .Names = character(0)) + +read_compressed_error <- function(e) { + e <- as.character(e) + compression <- sub(".*Support for codec '(.*)'.*", "\\1", e) + msg <- c( + sprintf("Unsupported compressed format %s", compression), + "\nTry setting the environment variable LIBARROW_MINIMAL=false and reinstalling", + "\nfor a more complete installation ", + sprintf("(including %s) or setting", compression), + sprintf("\nARROW_WITH_%s=ON and reinstalling to enable support for this codec.", toupper(compression)) + ) + stop(msg, call. = FALSE) +} diff --git a/r/tests/testthat/test-feather.R b/r/tests/testthat/test-feather.R index 52325c7f410..b0a9c6ff18e 100644 --- a/r/tests/testthat/test-feather.R +++ b/r/tests/testthat/test-feather.R @@ -196,3 +196,20 @@ test_that("Character vectors > 2GB can write to feather", { }) unlink(feather_file) + +# lz4 ---- + +ft_file <- test_path("golden-files/data-arrow_2.0.0_lz4.feather") + +test_that("Error messages are shown when the compression algorithm lz4 + is not found", { + if (codec_is_available("lz4")) { + d <- read_feather(ft_file) + expect_is(d, "data.frame") + } else { + expect_error( + read_feather(ft_file), + "Unsupported compressed format" + ) + } +}) diff --git a/r/tests/testthat/test-parquet.R b/r/tests/testthat/test-parquet.R index 4ac356f004d..89310d8af22 100644 --- a/r/tests/testthat/test-parquet.R +++ b/r/tests/testthat/test-parquet.R @@ -234,3 +234,11 @@ test_that("ParquetFileReader $ReadRowGroup(s) methods", { expect_true(reader$ReadRowGroups(c(0, 1), 0) == Table$create(x = 1:20)) expect_error(reader$ReadRowGroups(c(0, 1), 1)) }) + +test_that("Error messages are shown when the compression algorithm lz4/snappy + is not found", { + if (codec_is_available("snappy")) { + d <- read_parquet(pq_file) + expect_is(d, "data.frame") + } +})