From 9cff7ad863f2d32fd050b80e662c052ccdb41b72 Mon Sep 17 00:00:00 2001 From: emilio-berti Date: Tue, 9 Feb 2021 12:06:35 +0100 Subject: [PATCH] Fixing wwarnings --- R/en_path.R | 3 ++- R/enerscape.R | 19 ++++++++----------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/R/en_path.R b/R/en_path.R index 62215c9..cbf50f4 100644 --- a/R/en_path.R +++ b/R/en_path.R @@ -10,8 +10,9 @@ #' @param plot if TRUE plot the path #' @return A list with elements the path, its travel distance and energy costs. #' @examples -#' \dontrun{ +#' \donttest{ #' library(raster) +#' library(enerscape) #' data("volcano") #' dem <- raster(volcano) #' en <- enerscape(dem, 10, unit = "kcal", neigh = 16) diff --git a/R/enerscape.R b/R/enerscape.R index 3367f15..ec28e04 100644 --- a/R/enerscape.R +++ b/R/enerscape.R @@ -58,22 +58,19 @@ enerscape <- function( # as global variable and deleted before return. Deletion takes place in the # parent environment of the function. en_res <- raster::res(dem)[1] - # assign("enerscape", new.env()) - # assign("en_res", raster::res(dem)[1], envir = enerscape) message(" - Raster cells are assumed to have same horizontal and vertical", " resolution and with planar coordinate reference system (e.g. UTM)") - oldw <- getOption("warn") - options("warn" = -1) message(" | Calculating slope") - height <- gdistance::transition(dem, - function(x) { - x[2] - x[1] - }, - directions = neigh, - symm = FALSE) + height <- suppressWarnings( #this warning is printed as message before return + gdistance::transition(dem, + function(x) { + x[2] - x[1] + }, + directions = neigh, + symm = FALSE) + ) slope <- gdistance::geoCorrection(height, scl = FALSE) slope <- atan(slope) * 180 / pi #convert slope ratio to degrees - options("warn" = oldw) adj <- raster::adjacent(dem, 1:raster::ncell(dem), pairs = TRUE,