Skip to content

Commit

Permalink
Provide more examples in calculate_indices()
Browse files Browse the repository at this point in the history
  • Loading branch information
mikemahoney218 committed Aug 13, 2024
1 parent b1a15ba commit e2ec137
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
24 changes: 23 additions & 1 deletion R/calculate_indices.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,38 @@
#' names_suffix = "sentinel1"
#' )
#'
#' # Formulas aren't able to access most R functions or operators:
#' # Formulas aren't able to access most R functions or operators,
#' # in order to try and keep formulas from doing something bad:
#' example_indices <- filter_platforms(platforms = "Sentinel-1 (Dual Polarisation VV-VH)")[1, ]
#' example_indices$formula <- 'system("echo something bad")'
#' # So this will error:
#' try(
#' calculate_indices(
#' system.file("rasters/example_sentinel1.tif", package = "rsi"),
#' example_indices,
#' tempfile(fileext = ".tif")
#' )
#' )
#'
#' # Because of this, formulas which try to use most R functions
#' # will wind up erroring as well:
#' example_indices$formula <- "pmax(VH, VV)"
#' try(
#' calculate_indices(
#' system.file("rasters/example_sentinel1.tif", package = "rsi"),
#' example_indices,
#' tempfile(fileext = ".tif")
#' )
#' )
#'
#' # To fix this, pass the objects you want to use to `extra_objects`
#' calculate_indices(
#' system.file("rasters/example_sentinel1.tif", package = "rsi"),
#' example_indices,
#' tempfile(fileext = ".tif"),
#' extra_objects = list(pmax = pmax)
#' ) |>
#' suppressWarnings(classes = "rsi_extra_objects")
#'
#' @export
calculate_indices <- function(raster,
Expand Down
24 changes: 23 additions & 1 deletion man/calculate_indices.Rd

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

0 comments on commit e2ec137

Please sign in to comment.