Skip to content

Commit ad37d3f

Browse files
committed
Add example, add missing columns as required
1 parent 743d8eb commit ad37d3f

2 files changed

Lines changed: 37 additions & 0 deletions

File tree

R/run_rabimo.R

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@
1111
#' the list returned by \code{define_controls()}.
1212
#' @return data frame with columns as returned by Abimo
1313
#' @export
14+
#' @examples
15+
#' inputs_2020 <- kwb.rabimo::rabimo_inputs_2020
16+
#' inputs_2025 <- kwb.rabimo::rabimo_inputs_2025
17+
#' results_2020 <- kwb.rabimo::run_rabimo(inputs_2020$data, inputs_2020$config)
18+
#' results_2025 <- kwb.rabimo::run_rabimo(inputs_2025$data, inputs_2025$config)
1419
run_rabimo <- function(data, config, controls = define_controls())
1520
{
1621
# Provide functions and variables for debugging
@@ -25,6 +30,9 @@ run_rabimo <- function(data, config, controls = define_controls())
2530
`%>%` <- magrittr::`%>%`
2631
}
2732

33+
# If road-area-specific columns are missing, create them
34+
data <- handle_missing_columns(data)
35+
2836
# Provide function to access the list of controls
2937
control <- create_accessor(controls)
3038

@@ -312,6 +320,29 @@ run_rabimo <- function(data, config, controls = define_controls())
312320
)
313321
}
314322

323+
# handle_missing_columns -------------------------------------------------------
324+
handle_missing_columns <- function(data)
325+
{
326+
road_specific_columns <- c(
327+
"road_frac", "pvd_r", "swg_pvd_r",
328+
"srf1_pvd_r", "srf2_pvd_r", "srf3_pvd_r", "srf4_pvd_r"
329+
)
330+
331+
missing_road_columns <- setdiff(road_specific_columns, names(data))
332+
333+
if (length(missing_road_columns)) {
334+
for (column in missing_road_columns) {
335+
data[[column]] <- 0
336+
}
337+
}
338+
339+
if (! "main_frac" %in% names(data)) {
340+
data$main_frac <- 1
341+
}
342+
343+
data
344+
}
345+
315346
# get_climate: provides climate relevant input data ----------------------------
316347
get_climate <- function(input)
317348
{

man/run_rabimo.Rd

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)