Skip to content

Commit

Permalink
fixes for writeTo/filename2
Browse files Browse the repository at this point in the history
  • Loading branch information
ianmseddy committed Jul 8, 2024
1 parent 37446b9 commit 0b454e9
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 15 deletions.
2 changes: 1 addition & 1 deletion R/cache.R
Original file line number Diff line number Diff line change
Expand Up @@ -1045,7 +1045,7 @@ Cache <-
#' @keywords internal
.namesPostProcessFormals <- function() {
c(
"x", "filename1", "filename2", "studyArea", "rasterToMatch",
"x", "filename1", "writeTo", "studyArea", "rasterToMatch",
"overwrite", "useSAcrs", "useCache", "verbose"
)
}
Expand Down
5 changes: 5 additions & 0 deletions R/postProcessTo.R
Original file line number Diff line number Diff line change
Expand Up @@ -1273,6 +1273,11 @@ remapOldArgs <- function(..., fn = sys.function(sys.parent()), envir = parent.fr
verbose = getOption("reproducible.verbose")) {
forms <- formals(fn)
dots <- list(...)

if (!is.null(dots$filename2)) {
stop("filename2 arg is deprecated - please pass 'writeTo' instead (see `reproducible::writeTo`")
}

dots <- dots[!vapply(dots, is.null, FUN.VALUE = logical(1))]

ret <- list()
Expand Down
3 changes: 2 additions & 1 deletion R/preProcess.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
utils::globalVariables(c(
"reproducible.inputPaths", "successfulCheckSumFilePath", "successfulDir"
"reproducible.inputPaths", "successfulCheckSumFilePath", "successfulDir",
"destinationPathUser"
))

#' @param n Number of non-null arguments passed to `preProcess`.
Expand Down
5 changes: 2 additions & 3 deletions R/prepInputs.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ utils::globalVariables(c(
#' \item Crop using [cropTo()];
#' \item Project using [projectTo()];
#' \item Mask using [maskTo()];
#' \item Determine file name [determineFilename()] via `filename2`;
#' \item Optionally, write that file name to disk via [writeTo()].
#' \item write the file to disk via [writeTo()].
#' }
#'
#' NOTE: checksumming does not occur during the post-processing stage, as
Expand Down Expand Up @@ -311,7 +310,7 @@ utils::globalVariables(c(
#' studyArea = studyArea,
#' fun = "terra::vect",
#' destinationPath = dPath,
#' filename2 = "EcozoneFile.shp"
#' writeTo = "EcozoneFile.shp"
#' ) # passed to determineFilename
#'
#' terra::plot(shpEcozone[, 1])
Expand Down
2 changes: 1 addition & 1 deletion man/prepInputs.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/testthat/test-cache.R
Original file line number Diff line number Diff line change
Expand Up @@ -1717,7 +1717,7 @@ test_that("Issue 316 - writeOutputs in a non getwd dir", {
rasterToMatchLarge <- list()
for (i in 1:2) {
rasterToMatchLarge[[i]] <- Cache(writeOutputs, rasterToMatch,
filename2 = .suffix(
writeTo = .suffix(
file.path(tmpdir, "rasterToMatchLarge.tif"),
paste0("_", studyAreaName)
), datatype = "INT2U",
Expand Down
16 changes: 8 additions & 8 deletions tests/testthat/test-prepInputs.R
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ test_that("prepInputs doesn't work (part 1)", {
alsoExtract = reproducible::asPath(ecozoneFiles),
studyArea = StudyArea,
destinationPath = dPath,
filename2 = "EcozoneFile.shp",
writeTo = "EcozoneFile.shp",
useCache = FALSE
),
quick = "destinationPath"
Expand Down Expand Up @@ -1866,7 +1866,7 @@ test_that("writeOutputs saves factor rasters with .grd class to preserve levels"
tifTmp <- normPath(tifTmp)

b1 <- suppressWarnings(terra::writeRaster(a, filename = tifTmp, overwrite = TRUE)) # the GDAL>6 issue
b1a <- writeOutputs(a, filename2 = tifTmp)
b1a <- writeOutputs(a, writeTo = tifTmp)
expect_equivalent(b1, b1a)
expect_equivalent(b1[], b1a[])

Expand Down Expand Up @@ -1903,7 +1903,7 @@ test_that("rasters aren't properly resampled", {
targetFile = tiftemp1, rasterToMatch = terra::rast(tiftemp2),
destinationPath = dirname(tiftemp1), method = "bilinear",
datatype = "INT2S",
filename2 = tempfile(tmpdir = tmpdir, fileext = ".tif")
writeTo = tempfile(tmpdir = tmpdir, fileext = ".tif")
)
}) # about "raster layer has integer values"

Expand All @@ -1919,7 +1919,7 @@ test_that("rasters aren't properly resampled", {
out3 <- prepInputs(
targetFile = tiftemp3, rasterToMatch = terra::rast(tiftemp2),
destinationPath = dirname(tiftemp3),
filename2 = tempfile(tmpdir = tmpdir, fileext = ".tif")
writeTo = tempfile(tmpdir = tmpdir, fileext = ".tif")
)
expect_true(dataType2(out3) == "FLT4S")

Expand All @@ -1934,7 +1934,7 @@ test_that("rasters aren't properly resampled", {
out3 <- prepInputs(
targetFile = tiftemp4, rasterToMatch = terra::rast(tiftemp2),
destinationPath = dirname(tiftemp3),
filename2 = tempfile(tmpdir = tmpdir, fileext = ".tif")
writeTo = tempfile(tmpdir = tmpdir, fileext = ".tif")
)
expect_true(is(out3, rasterType()))
expect_true(identical(length(Filenames(out3)), 1L))
Expand All @@ -1947,7 +1947,7 @@ test_that("rasters aren't properly resampled", {
targetFile = tiftemp4, rasterToMatch = terra::rast(tiftemp2),
destinationPath = dirname(tiftemp3),
fun = rasterStackFn,
filename2 = c(
writeTo = c(
tempfile(tmpdir = tmpdir, fileext = ".grd"),
tempfile(tmpdir = tmpdir, fileext = ".grd")
)
Expand All @@ -1971,7 +1971,7 @@ test_that("rasters aren't properly resampled", {
targetFile = tiftemp5, rasterToMatch = terra::rast(tiftemp2),
destinationPath = dirname(tiftemp3),
fun = rasterStackFn,
filename2 = c(
writeTo = c(
tempfile(tmpdir = tmpdir, fileext = ".grd"),
tempfile(tmpdir = tmpdir, fileext = ".grd"),
tempfile(tmpdir = tmpdir, fileext = ".tif")
Expand All @@ -1987,7 +1987,7 @@ test_that("rasters aren't properly resampled", {
targetFile = tiftemp4, rasterToMatch = terra::rast(tiftemp2),
destinationPath = dirname(tiftemp3),
fun = rasterStackFn,
filename2 = c(
writeTo = c(
tempfile(tmpdir = tmpdir, fileext = ".grd"),
tempfile(tmpdir = tmpdir, fileext = ".grd")
)
Expand Down

0 comments on commit 0b454e9

Please sign in to comment.