Skip to content

Commit

Permalink
The glamour subdue me
Browse files Browse the repository at this point in the history
  • Loading branch information
geryan committed Jul 15, 2024
1 parent 9b86cdd commit 12c8912
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 0 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export(predict_sdm)
export(rastpointplot)
export(save_plot)
export(set_layer_names)
export(set_levels)
export(source_R)
export(split_rast)
export(standardise_rast)
Expand Down
37 changes: 37 additions & 0 deletions R/set_levels.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#' @title set levels
#' @description
#' Convenience function for setting `SpatRaster` levels names to enable setting in
#' piped workflows.
#'
#'
#' @param x `SpatRaster`
#' @param levs `data.frame`
#'
#' @return `SpatRaster`
#' @export
#'
#' @examples
#' \dontrun{
#' categorical_raster |>
#' set_levels(
#' levs = tribble(
#' ~value, ~category,
#' 30, "URBAN CENTRE",
#' 23, "DENSE URBAN CLUSTER",
#' 22, "SEMI-DENSE URBAN CLUSTER",
#' 21, "SUBURBAN OR PERI-URBAN",
#' 13, "RURAL CLUSTER",
#' 12, "LOW DENSITY RURAL",
#' 11, "VERY LOW DENSITY RURAL",
#' 10, "WATER"
#' )
#' ) %>%
#' as.data.frame()
#' }
#'
set_levels <- function(x, levs){

levels(x) <- levs

x
}
40 changes: 40 additions & 0 deletions man/set_levels.Rd

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

0 comments on commit 12c8912

Please sign in to comment.