From 78e8cdfc016927a6435418bc5b1e4f6d8803b161 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 18 Oct 2025 18:30:24 +0000 Subject: [PATCH 1/3] Initial plan From d43d04f4ad72e6f324849355d1d1775955f50b43 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 18 Oct 2025 18:34:08 +0000 Subject: [PATCH 2/3] Fix file asset access issues on CRAN - Add skip_if checks in test-wbt_source.R to handle missing sample data - Improve sample_dem_data() to use tempdir() when package dir is read-only Co-authored-by: brownag <20842828+brownag@users.noreply.github.com> --- R/whitebox-package.R | 28 +++++++++++++++++++++------- tests/testthat/test-wbt_source.R | 2 ++ 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/R/whitebox-package.R b/R/whitebox-package.R index 350b5d94..58be5fe8 100644 --- a/R/whitebox-package.R +++ b/R/whitebox-package.R @@ -96,16 +96,30 @@ sample_dem_data <- function(destfile = file.path(system.file('extdata', package= } } if (fp == "") { - try(download.file("https://github.com/opengeos/whiteboxR/raw/master/inst/extdata/DEM.tif", - destfile = destfile, - mode = "wb", ...)) + # If file doesn't exist, try to download it + # First, determine the best location for the download if (missing(destfile)) { - fp <- system.file("extdata/DEM.tif", package = "whitebox")[1] - } else { - if (file.exists(destfile)) { - fp <- destfile + # Check if package installation directory is writable + pkg_extdata <- system.file('extdata', package="whitebox") + if (nzchar(pkg_extdata) && file.access(pkg_extdata, 2) == 0) { + # Package extdata is writable, use it + destfile <- file.path(pkg_extdata, 'DEM.tif') + } else { + # Package extdata is not writable (e.g., on CRAN), use temp directory + destfile <- file.path(tempdir(), 'whitebox_DEM.tif') } } + + result <- try(download.file("https://github.com/opengeos/whiteboxR/raw/master/inst/extdata/DEM.tif", + destfile = destfile, + mode = "wb", ...), silent = TRUE) + + if (!inherits(result, "try-error") && file.exists(destfile)) { + fp <- destfile + } else { + # Download failed, check one more time if file appeared in package directory + fp <- system.file("extdata/DEM.tif", package = "whitebox")[1] + } } fp } diff --git a/tests/testthat/test-wbt_source.R b/tests/testthat/test-wbt_source.R index 82d9df5a..5a72759d 100644 --- a/tests/testthat/test-wbt_source.R +++ b/tests/testthat/test-wbt_source.R @@ -3,6 +3,7 @@ test_that("wbt_source (raster) works", { skip_if_not_installed("terra") f <- sample_dem_data() + skip_if(f == "") # raster source from geotiff path src <- wbt_source(f) @@ -60,6 +61,7 @@ test_that("wbt_source (vector) works", { skip_if_not_installed("terra") f <- sample_soils_data() + skip_if(f == "") # vector source from shapefile src <- wbt_source(f) From 45697ed42a6022c7615f7e5f1ba6520478ed7583 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 18 Oct 2025 18:37:31 +0000 Subject: [PATCH 3/3] Fix .Rbuildignore to include inst/extdata/DEM.tif The pattern ^.*\.tif$ was excluding ALL .tif files including the required sample data file inst/extdata/DEM.tif. Changed to ^[^/]*\.tif$ to only exclude .tif files in the package root directory. Co-authored-by: brownag <20842828+brownag@users.noreply.github.com> --- .Rbuildignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.Rbuildignore b/.Rbuildignore index da3f90d8..fc689adf 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -11,7 +11,7 @@ ^\.travis\.yml$ ^\.github$ ^WhiteboxTools_linux_amd64\.zip$ -^.*\.tif$ +^[^/]*\.tif$ ^.*\.json$ ^doc$ ^Meta$