diff --git a/NEWS.md b/NEWS.md index fc06c95..a9ada9e 100644 --- a/NEWS.md +++ b/NEWS.md @@ -10,7 +10,7 @@ write_ods(list("some_car_data" = mtcars, "some_flower_data" = iris)) ## bug fixes -* Fix #157 `list_fods_sheets()` cannot accept `~` as path +* Fix #157 `list_fods_sheets()` and `read_fods()` cannot accept `~` as path # readODS 2.05 diff --git a/R/read_ods.R b/R/read_ods.R index 9a14436..fdc76c0 100644 --- a/R/read_ods.R +++ b/R/read_ods.R @@ -182,6 +182,7 @@ strings_as_factors, verbose, as_tibble) + path <- normalizePath(path) if (flat) { .get_sheet_names_func <- get_flat_sheet_names_ .read_ods_func <- read_flat_ods_ @@ -317,7 +318,7 @@ read_fods <- function(path, as_tibble = TRUE, .name_repair = "unique") { ## Should use match.call but there's a weird bug if one of the variable names is 'file' - .read_ods(path = path, + .read_ods(path = normalizePath(path, mustWork = FALSE), sheet = sheet, col_names = col_names, col_types = col_types, diff --git a/tests/testthat/test_read_fods.R b/tests/testthat/test_read_fods.R index dd90120..7f33666 100644 --- a/tests/testthat/test_read_fods.R +++ b/tests/testthat/test_read_fods.R @@ -13,4 +13,12 @@ test_that("Error when not correct", { test_that("Return blank/error if mangled FODS", { expect_warning(read_fods("../testdata/norows.fods")) expect_warning(read_fods("../testdata/nocells.fods")) -}) \ No newline at end of file +}) + +test_that("fix #157", { + skip_if(file.access("~/", 2) != 0) + file.copy("../testdata/flat.fods", "~/flat_you_must_not_use_this_path.fods") + expect_error(read_fods("~/flat_you_must_not_use_this_path.fods"), NA) + expect_error(read_fods("~/flat_you_must_not_use_this_path_not.fods")) + on.exit(unlink("~/flat_you_must_not_use_this_path.fods")) +})