1
0
mirror of https://github.com/msberends/AMR.git synced 2025-07-09 15:01:51 +02:00

(v1.2.0.9011) mo_domain(), improved error handling

This commit is contained in:
2020-06-22 11:18:40 +02:00
parent e88d7853f5
commit 93a158aebd
49 changed files with 523 additions and 590 deletions

View File

@ -123,18 +123,12 @@ resistance_predict <- function(x,
info = interactive(),
...) {
if (nrow(x) == 0) {
stop("This table does not contain any observations.")
}
stop_ifnot(is.data.frame(x), "`x` must be a data.frame")
stop_if(any(dim(x) == 0), "`x` must contain rows and columns")
stop_if(is.null(model), 'choose a regression model with the `model` parameter, e.g. resistance_predict(..., model = "binomial")')
stop_ifnot(col_ab %in% colnames(x),
"column `", col_ab, "` not found")
if (is.null(model)) {
stop('Choose a regression model with the `model` parameter, e.g. resistance_predict(..., model = "binomial").')
}
if (!col_ab %in% colnames(x)) {
stop("Column ", col_ab, " not found.")
}
dots <- unlist(list(...))
if (length(dots) != 0) {
# backwards compatibility with old parameters
@ -150,16 +144,12 @@ resistance_predict <- function(x,
# -- date
if (is.null(col_date)) {
col_date <- search_type_in_df(x = x, type = "date")
stop_if(is.null(col_date), "`col_date` must be set")
}
if (is.null(col_date)) {
stop("`col_date` must be set.", call. = FALSE)
}
stop_ifnot(col_date %in% colnames(x),
"column `", col_date, "` not found")
if (!col_date %in% colnames(x)) {
stop("Column ", col_date, " not found.")
}
# no grouped tibbles, mutate will throw errors
# no grouped tibbles
x <- as.data.frame(x, stringsAsFactors = FALSE)
year <- function(x) {
@ -192,10 +182,8 @@ resistance_predict <- function(x,
df <- subset(df, sum(df$R + df$S, na.rm = TRUE) >= minimum)
df_matrix <- as.matrix(df[, c("R", "S"), drop = FALSE])
if (NROW(df) == 0) {
stop("There are no observations.")
}
stop_if(NROW(df) == 0, "there are no observations")
year_lowest <- min(df$year)
if (is.null(year_min)) {
year_min <- year_lowest
@ -248,7 +236,7 @@ resistance_predict <- function(x,
se <- predictmodel$se.fit
} else {
stop("No valid model selected. See ?resistance_predict.")
stop("no valid model selected. See ?resistance_predict.")
}
# prepare the output dataframe
@ -355,12 +343,9 @@ ggplot_rsi_predict <- function(x,
main = paste("Resistance Prediction of", x_name),
ribbon = TRUE,
...) {
stopifnot_installed_package("ggplot2")
if (!"resistance_predict" %in% class(x)) {
stop("`x` must be a resistance prediction model created with resistance_predict().")
}
stop_ifnot_installed("ggplot2")
stop_ifnot(inherits(x, "resistance_predict"), "`x` must be a resistance prediction model created with resistance_predict()")
x_name <- paste0(ab_name(attributes(x)$ab), " (", attributes(x)$ab, ")")