Skip to content

Commit

Permalink
Fix #354 (#397)
Browse files Browse the repository at this point in the history
* Fix #354

But it doesn't fix #395 and #396

* Old R bug on Tar
  • Loading branch information
chainsawriot committed Apr 25, 2024
1 parent 479a765 commit 2fb1373
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 30 deletions.
42 changes: 14 additions & 28 deletions tests/testthat/test_compress.R
Expand Up @@ -9,32 +9,18 @@ test_that("Recognize compressed file types", {
})

test_that("Export to compressed (zip) / import", {
withr::with_tempfile("iris_path", fileext = ".csv.zip", code = {
e1 <- export(iris, iris_path)
expect_true(file.exists(iris_path))
expect_true(is.data.frame(import(iris_path)))
expect_true(is.data.frame(import(iris_path)))
expect_true(is.data.frame(import(iris_path, which = 1)))
base_file_name <- gsub("\\.zip", "", basename(iris_path))
expect_true(is.data.frame(import(iris_path, which = base_file_name)))
})
skip_if(getRversion() <= "4.0")
##formats <- c("zip", "tar", "gzip", "bzip2", "xz")
formats <- c("zip", "tar") ## 395 #396
for (format in formats) {
withr::with_tempfile("iris_path", fileext = paste0(".csv.", format), code = {
e1 <- export(iris, iris_path)
expect_true(file.exists(iris_path))
expect_true(is.data.frame(import(iris_path)))
expect_true(is.data.frame(import(iris_path)))
expect_true(is.data.frame(import(iris_path, which = 1)))
base_file_name <- gsub(paste0("\\.", format), "", basename(iris_path))
expect_true(is.data.frame(import(iris_path, which = base_file_name)))
})
}
})

test_that("Export to compressed (tar)", {
withr::with_tempfile("iris_path", fileext = ".csv.tar", code = {
e2 <- export(iris, iris_path)
expect_true(file.exists(iris_path))
## tar export does not work due to: https://bugs.r-project.org/bugzilla3/show_bug.cgi?id=16716
##expect_true(is.data.frame(import("iris.csv.tar")))
})
})

## test_that("Import from compressed", {
## expect_true(is.data.frame(import("iris.csv.zip")))
## expect_true(is.data.frame(import("iris.csv.zip", which = 1)))
## expect_true(is.data.frame(import("iris.csv.zip", which = "iris.csv")))
## # tar export does not work due to: https://bugs.r-project.org/bugzilla3/show_bug.cgi?id=16716
## #expect_true(is.data.frame(import("iris.csv.tar")))
## })

## unlink("iris.csv.tar")
4 changes: 2 additions & 2 deletions tests/testthat/test_format_html.R
Expand Up @@ -23,9 +23,9 @@ test_that("Export to and import from HTML", {
test_that("Export to HTML with ampersands",{
withr::with_tempfile("iris_file", fileext = ".html", code = {

iris$`R & D` <- paste(sample(letters,nrow(iris),rep = TRUE),
iris$`R & D` <- paste(sample(letters,nrow(iris), replace = TRUE),
"&",
sample(LETTERS,nrow(iris),rep = TRUE))
sample(LETTERS,nrow(iris), replace = TRUE))
export(iris, iris_file)
expect_true(file.exists(iris_file),
label = "export to html with ampersands works")
Expand Down

0 comments on commit 2fb1373

Please sign in to comment.