Skip to content

Commit

Permalink
docs, args, deps, cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
brownag committed Dec 20, 2023
1 parent 1eb4be7 commit 987d8c0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
14 changes: 7 additions & 7 deletions R/fetchSoilGrids.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,12 @@
#' @param depth_intervals Default: `"0-5"`, `"5-15"`, `"15-30"`, `"30-60"`, `"60-100"`, `"100-200"`
#' @param variables Default: `"bdod"`, `"cec"`, `"cfvo"`, `"clay"`, `"nitrogen"`, `"phh2o"`, `"sand"`, `"silt"`, `"soc"`, `"ocd"`. Optionally `"ocs"` for 0 to 30 cm interval.
#' @param grid Download subset of SoilGrids Cloud Optimized GeoTIFF? Default: FALSE
#' @param filename Only used when `grid=TRUE`. If `NULL` defaults to a temporary file with .tif extension.
#' @param filename Only used when `grid=TRUE`. If `NULL` defaults to an in-memory raster, or temporary file if result does not fit in memory.
#' @param overwrite Only used when `grid=TRUE`. Default: `FALSE`
#' @param target_resolution Only used when `grid=TRUE`. Default: `c(250, 250)` (250m x 250m pixels)
#' @param summary_type Only used when `grid=TRUE`. One or more of `"Q0.05"`, `"Q0.5"`, `"Q0.95"`, `"mean"`; these are summary statistics that
#' corresponding to 5th, 50th and 95th percentiles and mean value for selected `variables`.
#' @param ... Additional arguments passed to `terra::writeRaster()` when `grid=TRUE`.
#' @param verbose Print messages? Default: `FALSE`
#' @param progress logical, give progress when iterating over multiple requests; Default: `FALSE`
#'
Expand All @@ -51,7 +52,6 @@
#'
#' @author Andrew G. Brown
#' @examplesIf curl::has_internet()
#' @examples
#' \dontrun{
#' library(aqp)
#'
Expand Down Expand Up @@ -99,6 +99,7 @@ fetchSoilGrids <- function(x,
overwrite = TRUE,
target_resolution = c(250, 250),
summary_type = c("Q0.05", "Q0.5", "Q0.95", "mean"),
...,
verbose = FALSE,
progress = FALSE) {

Expand All @@ -122,6 +123,7 @@ fetchSoilGrids <- function(x,
target_resolution = target_resolution,
depth = depth_intervals,
summary_type = summary_type,
...,
verbose = verbose))
} else {
# only supporting POINT geometry for now
Expand Down Expand Up @@ -295,8 +297,10 @@ fetchSoilGrids <- function(x,
summary_type = c("Q0.05", "Q0.5", "Q0.95", "mean"),
variables = c("bdod", "cec", "cfvo", "clay", "nitrogen",
"phh2o", "sand", "silt", "soc"),
...,
verbose = TRUE) {

stopifnot(requireNamespace("terra"))
stopifnot(requireNamespace("sf"))

if (!all(substr(depth, nchar(depth) - 2, nchar(depth)) == "cm")) {
Expand Down Expand Up @@ -365,11 +369,7 @@ fetchSoilGrids <- function(x,
names(stk) <- vardepth

if (!is.null(filename)) {
terra::writeRaster(stk, filename = filename, overwrite = overwrite)
}

if (interactive()) {
terra::plot(stk)
terra::writeRaster(stk, filename = filename, overwrite = overwrite, ...)
}

# apply conversion factor
Expand Down
7 changes: 5 additions & 2 deletions man/fetchSoilGrids.Rd

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

0 comments on commit 987d8c0

Please sign in to comment.