Skip to content
Merged
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$
Comment thread
brownag marked this conversation as resolved.
^.*\.tif$
^(?!inst/extdata/DEM\.tif$).*\.tiff?$
Comment thread
brownag marked this conversation as resolved.
^.*\.json$
Comment thread
brownag marked this conversation as resolved.
^doc$
^Meta$
Expand Down
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: whitebox
Type: Package
Title: 'WhiteboxTools' R Frontend
Version: 2.4.2
Version: 2.4.3
Description: An R frontend for the 'WhiteboxTools' library, which is an advanced geospatial data analysis platform developed by Prof. John Lindsay at the University of Guelph's Geomorphometry and Hydrogeomatics Research Group. 'WhiteboxTools' can be used to perform common geographical information systems (GIS) analysis operations, such as cost-distance analysis, distance buffering, and raster reclassification. Remote sensing and image processing tasks include image enhancement (e.g. panchromatic sharpening, contrast adjustments), image mosaicing, numerous filtering operations, simple classification (k-means), and common image transformations. 'WhiteboxTools' also contains advanced tooling for spatial hydrological analysis (e.g. flow-accumulation, watershed delineation, stream network analysis, sink removal), terrain analysis (e.g. common terrain indices such as slope, curvatures, wetness index, hillshading; hypsometric analysis; multi-scale topographic position analysis), and LiDAR data processing. Suggested citation: Lindsay (2016) <doi:10.1016/j.cageo.2016.07.003>.
Authors@R: c(person("Qiusheng", "Wu", email = "giswqs@gmail.com", role = c("aut")),
person("Andrew", "Brown", email = "brown.andrewg@gmail.com", role = c("aut", "cre"), comment=c(ORCID="0000-0002-4565-533X")))
Expand Down
16 changes: 16 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
# whitebox 2.4.3

* Fix for CRAN check (#135)

* GeoTIFF DEM sample data (_extdata/DEM.tif_) previously excluded, along with all other TIFF files, by _.Rbuildignore_ is now explicitly included

* Fix for behavior of `sample_dem_data()` `destfile` argument:

* Errors thrown from invalid sources from new `wbt_source()` (introduced in v2.4.2) revealed an underlying issue with sample data assets. Invalid source errors are now intentionally captured and tested, and inclusion of the extdata file should ensure other parts of tests work as expected

* When `destfile` unset and no local file present, `sample_dem_data()` no longer attempts to download and write to the user package library (**which is read-only on CRAN**)

* `destfile` now intended for copying the sample dataset from package _extdata_ folder, for workflows that need the sample data outside of the package library

* `sample_soils_data()` now supports `destfile` (just like `sample_dem_data()`)

# whitebox 2.4.2

* `wbt_source()`: now accepts `tmpdir` argument which defaults to `tempdir()` (not `getwd()` or `wbt_wd()`) that is used for storing the intermediate shapefiles needed for WhiteboxTools
Expand Down
1 change: 1 addition & 0 deletions R/wbt.R
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,7 @@ wbt_max_procs <- function(max_procs = NULL) {
#' @export
#' @keywords General
#' @rdname install_whitebox
#' @importFrom utils download.file
wbt_install <- function(pkg_dir = wbt_data_dir(), platform = NULL, force = FALSE, remove = FALSE) {

stopifnot(is.logical(force))
Expand Down
55 changes: 32 additions & 23 deletions R/whitebox-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ whitebox.env <- new.env()
#' Get a file path to DEM.tif or STATSGO2.shp stored in extdata subfolder of whitebox package installation directory.
#'
#' @param destfile Path to target location of sample data. Will be downloaded if does not exist. Defaults to file path of extdata subfolder of whitebox package installation directory.
#' @param ... additional arguments to download.file()
#' @param ... additional arguments to `file.copy()` e.g. `overwrite`
#'
#' @return character.
#' @export
Expand All @@ -84,36 +84,45 @@ whitebox.env <- new.env()
#' wbt_slope(sample_dem_data(), output = "slope.tif")
#' }
#' unlink(c('slope.tif', 'settings.json'))
#' @importFrom utils download.file
sample_dem_data <- function(destfile = file.path(system.file('extdata', package="whitebox"), 'DEM.tif'), ...) {
if (missing(destfile)) {
fp <- system.file("extdata/DEM.tif", package = "whitebox")[1]
} else {
if (!file.exists(destfile)) {
fp <- ""
} else {
fp <- destfile
sample_dem_data <- function(destfile = NULL, ...) {
fp <- system.file("extdata", "DEM.tif", package = "whitebox")[1]
if (!missing(destfile)) {
dn <- dirname(destfile)
if (!dir.exists(dn)) {
dir.create(dn, showWarnings = FALSE, recursive = TRUE)
}
}
if (fp == "") {
try(download.file("https://github.com/opengeos/whiteboxR/raw/master/inst/extdata/DEM.tif",
destfile = destfile,
mode = "wb", ...))
if (missing(destfile)) {
fp <- system.file("extdata/DEM.tif", package = "whitebox")[1]
file.copy(fp, destfile, ...)
if (file.exists(destfile)) {
fp <- destfile
} else {
if (file.exists(destfile)) {
fp <- destfile
}
stop(sprintf("Failed to copy '%s' to '%s'", fp, destfile))
}
}
fp
normalizePath(fp, mustWork = FALSE)
}

#' @export
#' @rdname extdata-gis
sample_soils_data <- function() {
system.file("extdata", "STATSGO2.shp", package = "whitebox")[1]
sample_soils_data <- function(destfile = NULL, ...) {
fp <- system.file("extdata", "STATSGO2.shp", package = "whitebox")[1]
if (!missing(destfile)) {
dn <- dirname(destfile)
if (!dir.exists(dn)) {
dir.create(dn, showWarnings = FALSE, recursive = TRUE)
}
fn <- list.files(dirname(fp), pattern = "STATSGO2", full.names = TRUE)
bn <- tools::file_path_sans_ext(basename(destfile))
fps <- file.path(dirname(destfile),
paste0(bn, ".", tools::file_ext(fn)))
file.copy(fn, fps, ...)
if (all(file.exists(fps))) {
fp <- fps[grep("\\.shp$", fps)[1]]
} else {
stop(sprintf("Failed to copy '%s' to '%s'", fp,
file.path(dirname(destfile), paste0(bn, ".shp"))))
Comment thread
brownag marked this conversation as resolved.
}
}
normalizePath(fp, mustWork = FALSE)
}

# The following block is used by usethis to automatically manage
Expand Down
9 changes: 3 additions & 6 deletions man/extdata-gis.Rd

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

6 changes: 6 additions & 0 deletions tests/testthat/test-wbt_source.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@ test_that("wbt_source (raster) works", {

skip_if_not_installed("terra")

expect_error(wbt_source("does_not_exist.tif"))

f <- sample_dem_data()

skip_if(!file.exists(f))

# raster source from geotiff path
src <- wbt_source(f)

Expand Down Expand Up @@ -61,6 +65,8 @@ test_that("wbt_source (vector) works", {

f <- sample_soils_data()

skip_if(!file.exists(f))

# vector source from shapefile
src <- wbt_source(f)

Expand Down
Loading