Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
^\.travis\.yml$
^\.github$
^WhiteboxTools_linux_amd64\.zip$
^.*\.tif$
^[^/]*\.tif$
^.*\.json$
^doc$
^Meta$
Expand Down
28 changes: 21 additions & 7 deletions R/whitebox-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test-wbt_source.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
Loading