Skip to content

Commit

Permalink
Soft-deprecate zip() and zip_append()
Browse files Browse the repository at this point in the history
  • Loading branch information
gaborcsardi committed Mar 11, 2019
1 parent 027d05f commit ef57e0e
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 14 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@

# dev

* `zip()` and `zip_append()` are now soft-deprecated, please use
`zipr()` and `zipr_append()` instead.

# 2.0.0

* New `zipr()` and `zipr_append()`, they always store relative file names
Expand Down
9 changes: 9 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,12 @@ need_packages <- function(pkgs, what = "this function") {
}
}
}

deprecated <- function(id, msg) {
if (isTRUE(zip_data$deprecated[[id]])) return(invisible())
zip_data$deprecated <- as.list(zip_data$deprecated)
zip_data$deprecated[[id]] <- TRUE
m <- simpleMessage(paste0("Note: ", msg, "\n"))
class(m) <- c("deprecated", class(m))
message(m)
}
4 changes: 4 additions & 0 deletions R/zip.R
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ NULL
#' zip_list(zipfile)

zip <- function(zipfile, files, recurse = TRUE, compression_level = 9) {
deprecated("zip", "zip::zip() is deprecated, please use zip::zipr() instead")
zip_internal(zipfile, files, recurse, compression_level, append = FALSE,
keep_path = TRUE)
}
Expand All @@ -115,6 +116,9 @@ zipr <- function(zipfile, files, recurse = TRUE, compression_level = 9) {

zip_append <- function(zipfile, files, recurse = TRUE,
compression_level = 9) {
deprecated(
"zip_append",
"zip::zip_append() is deprecated, please use zip::zipr_append instead")
zip_internal(zipfile, files, recurse, compression_level, append = TRUE,
keep_path = TRUE)
}
Expand Down
8 changes: 8 additions & 0 deletions tests/testthat/helper.R
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,11 @@ make_a_zip <- function(mtime = Sys.time(), envir = parent.frame()) {
zipr(zip, tmp)
list(zip = zip, ex = tmp)
}

expect_deprecated <- function(expr) {
expect_silent(
withCallingHandlers(
expr,
"deprecated" = function(e) invokeRestart("muffleMessage"))
)
}
28 changes: 14 additions & 14 deletions tests/testthat/test-zip.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ test_that("can compress single directory", {

zipfile <- tempfile(fileext = ".zip")

expect_silent(
expect_deprecated(
withr::with_dir(
dirname(tmp),
zip(zipfile, basename(tmp))
Expand All @@ -36,7 +36,7 @@ test_that("can compress single file", {

zipfile <- tempfile(fileext = ".zip")

expect_silent(
expect_deprecated(
withr::with_dir(
dirname(tmp),
zip(zipfile, basename(tmp))
Expand All @@ -58,7 +58,7 @@ test_that("can compress multiple files", {

zipfile <- tempfile(fileext = ".zip")

expect_silent(
expect_deprecated(
withr::with_dir(
dirname(tmp1),
zip(zipfile, basename(c(tmp1, tmp2)))
Expand All @@ -84,7 +84,7 @@ test_that("can compress multiple directories", {

zipfile <- tempfile(fileext = ".zip")

expect_silent(
expect_deprecated(
withr::with_dir(
dirname(tmp1),
zip(zipfile, basename(c(tmp1, tmp2)))
Expand Down Expand Up @@ -127,7 +127,7 @@ test_that("can compress files and directories", {

zipfile <- tempfile(fileext = ".zip")

expect_silent(
expect_deprecated(
withr::with_dir(
dirname(tmp),
zip(zipfile, basename(c(file1, tmp, file2)))
Expand Down Expand Up @@ -184,14 +184,14 @@ test_that("compression level is used", {
zipfile1 <- tempfile(fileext = ".zip")
zipfile2 <- tempfile(fileext = ".zip")

expect_silent(
expect_deprecated(
withr::with_dir(
dirname(file),
zip(zipfile1, basename(file), compression_level = 1)
)
)

expect_silent(
expect_deprecated(
withr::with_dir(
dirname(file),
zip(zipfile2, basename(file), compression_level = 9)
Expand Down Expand Up @@ -220,7 +220,7 @@ test_that("can append a directory to an archive", {

zipfile <- tempfile(fileext = ".zip")

expect_silent(
expect_deprecated(
withr::with_dir(
dirname(tmp),
zip(zipfile, basename(tmp))
Expand All @@ -239,7 +239,7 @@ test_that("can append a directory to an archive", {
cat("first file2", file = file.path(tmp2, "file3"))
cat("second file2", file = file.path(tmp2, "file4"))

expect_silent(
expect_deprecated(
withr::with_dir(
dirname(tmp),
zip_append(zipfile, basename(tmp2))
Expand All @@ -264,7 +264,7 @@ test_that("can append a file to an archive", {

zipfile <- tempfile(fileext = ".zip")

expect_silent(
expect_deprecated(
withr::with_dir(
dirname(tmp),
zip(zipfile, basename(tmp))
Expand All @@ -281,7 +281,7 @@ test_that("can append a file to an archive", {

cat("first file2", file = file1 <- tempfile())

expect_silent(
expect_deprecated(
withr::with_dir(
dirname(tmp),
zip_append(zipfile, basename(file1))
Expand All @@ -306,7 +306,7 @@ test_that("can append files and directories to an archive", {

zipfile <- tempfile(fileext = ".zip")

expect_silent(
expect_deprecated(
withr::with_dir(
dirname(tmp),
zip(zipfile, basename(tmp))
Expand All @@ -326,7 +326,7 @@ test_that("can append files and directories to an archive", {
cat("another", file = file.path(tmp2, "file3"))
cat("and another", file = file.path(tmp2, "file4"))

expect_silent(
expect_deprecated(
withr::with_dir(
dirname(tmp),
zip_append(zipfile, basename(c(file1, tmp2)))
Expand All @@ -352,7 +352,7 @@ test_that("empty directories are archived as directories", {
dir.create(file.path(tmp, "foo", "bar2"))
cat("contents\n", file = file.path(tmp, "foo", "file1"))

expect_silent(
expect_deprecated(
withr::with_dir(
dirname(tmp),
zip(zipfile, basename(tmp))
Expand Down

0 comments on commit ef57e0e

Please sign in to comment.