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
7 changes: 5 additions & 2 deletions r/R/feather.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 8 additions & 2 deletions r/R/parquet.R
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
13 changes: 13 additions & 0 deletions r/R/util.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
17 changes: 17 additions & 0 deletions r/tests/testthat/test-feather.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
}
})
8 changes: 8 additions & 0 deletions r/tests/testthat/test-parquet.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
})