Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .lintr
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ linters: linters_with_tags(
implicit_assignment_linter = NULL, # false positives with data.table :=
strings_as_factors_linter = NULL, # R 4.0+ defaults to stringsAsFactors = FALSE
one_call_pipe_linter = NULL, # stylistic preference
keyword_quote_linter = NULL, # stylistic preference
unnecessary_concatenation_linter = NULL, # intentional patterns
library_call_linter = NULL, # intentional patterns in scripts
pipe_consistency_linter = NULL # one_call_pipe_linter exclusion triggers false positives
Expand Down
8 changes: 3 additions & 5 deletions R/class-forecast-binary.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,24 +69,22 @@
forecast, c("sample_id", "quantile_level")
)
if (!columns_correct) {
#nolint start: keyword_quote_linter
cli_abort(
c(
"!" = "Checking `forecast`: Input looks like a binary forecast, but an
`!` = "Checking `forecast`: Input looks like a binary forecast, but an
additional column called `sample_id` or `quantile` was found.",
"i" = "Please remove the column."
`i` = "Please remove the column."

Check warning on line 76 in R/class-forecast-binary.R

View workflow job for this annotation

GitHub Actions / lint-changed-files

file=R/class-forecast-binary.R,line=76,col=9,[keyword_quote_linter] Only quote named arguments to functions if necessary, i.e., if the name is not a valid R symbol (see ?make.names).
)
)
}
input_check <- check_input_binary(forecast$observed, forecast$predicted)
if (!isTRUE(input_check)) {
cli_abort(
c(
"!" = "Checking `forecast`: Input looks like a binary forecast, but
`!` = "Checking `forecast`: Input looks like a binary forecast, but
found the following issue: {input_check}"
)
)
#nolint end
}
return(invisible(NULL))
}
Expand Down
2 changes: 1 addition & 1 deletion R/class-forecast-nominal.R
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ assert_forecast.forecast_nominal <- function(
if (!all(complete$correct)) {
first_issue <- complete[(correct), ..forecast_unit][1]
first_issue <- lapply(first_issue, FUN = as.character)
#nolint start: keyword_quote_linter object_usage_linter duplicate_argument_linter
#nolint start: object_usage_linter duplicate_argument_linter
issue_location <- paste(names(first_issue), "==", first_issue)
cli_abort(
c(`!` = "Found incomplete forecasts",
Expand Down
2 changes: 1 addition & 1 deletion R/class-forecast-ordinal.R
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ assert_forecast.forecast_ordinal <- function(
if (!all(complete$correct)) {
first_issue <- complete[(correct), ..forecast_unit][1]
first_issue <- lapply(first_issue, FUN = as.character)
#nolint start: keyword_quote_linter object_usage_linter duplicate_argument_linter
#nolint start: object_usage_linter duplicate_argument_linter
issue_location <- paste(names(first_issue), "==", first_issue)
cli_abort(
c(`!` = "Found incomplete forecasts",
Expand Down
4 changes: 2 additions & 2 deletions R/class-forecast-point.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ assert_forecast.forecast_point <- function(
) {
forecast <- assert_forecast_generic(forecast, verbose)
assert_forecast_type(forecast, actual = "point", desired = forecast_type)
#nolint start: keyword_quote_linter object_usage_linter
#nolint start: object_usage_linter
input_check <- check_input_point(forecast$observed, forecast$predicted)
if (!isTRUE(input_check)) {
cli_abort(
c(
"!" = "Checking `forecast`: Input looks like a point forecast, but found
`!` = "Checking `forecast`: Input looks like a point forecast, but found
the following issue: {input_check}"
)
)
Expand Down
30 changes: 12 additions & 18 deletions R/class-forecast.R
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,11 @@
forecast, forecast_type = NULL, verbose = TRUE, ...
) {
cli_abort(
#nolint start: keyword_quote_linter
c(
"!" = "The input needs to be a valid forecast object.",
"i" = "Please convert to `forecast` object first by calling the
`!` = "The input needs to be a valid forecast object.",
`i` = "Please convert to `forecast` object first by calling the

Check warning on line 84 in R/class-forecast.R

View workflow job for this annotation

GitHub Actions / lint-changed-files

file=R/class-forecast.R,line=84,col=7,[keyword_quote_linter] Only quote named arguments to functions if necessary, i.e., if the name is not a valid R symbol (see ?make.names).
appropriate {.fn as_forecast_<type>} function)."
)
#nolint end
)
}

Expand Down Expand Up @@ -117,7 +115,7 @@
if (problem) {
cli_abort(
c(
"!" = "Found columns `quantile_level` and `sample_id`.
`!` = "Found columns `quantile_level` and `sample_id`.
Only one of these is allowed"
)
)
Expand All @@ -136,23 +134,21 @@
# check whether there are any NA values
if (anyNA(data)) {
if (nrow(na.omit(data)) == 0) {
#nolint start: keyword_quote_linter
cli_abort(
c(
"!" = "After removing rows with NA values in the data, no forecasts
`!` = "After removing rows with NA values in the data, no forecasts
are left."
)
)
}
if (verbose) {
cli_inform(
c(
"i" = "Some rows containing NA values may be removed.
`i` = "Some rows containing NA values may be removed.

Check warning on line 147 in R/class-forecast.R

View workflow job for this annotation

GitHub Actions / lint-changed-files

file=R/class-forecast.R,line=147,col=11,[keyword_quote_linter] Only quote named arguments to functions if necessary, i.e., if the name is not a valid R symbol (see ?make.names).
This is fine if not unexpected."
)
)
}
#nolint end
}

return(data[])
Expand Down Expand Up @@ -292,15 +288,13 @@
)
if (inherits(validation, "try-error")) {
cli_warn(
#nolint start: keyword_quote_linter
c(
"!" = "Error in validating forecast object: {validation}.",
"i" = "Note this error is sometimes related to `data.table`s `print`.
`!` = "Error in validating forecast object: {validation}.",
`i` = "Note this error is sometimes related to `data.table`s `print`.

Check warning on line 293 in R/class-forecast.R

View workflow job for this annotation

GitHub Actions / lint-changed-files

file=R/class-forecast.R,line=293,col=11,[keyword_quote_linter] Only quote named arguments to functions if necessary, i.e., if the name is not a valid R symbol (see ?make.names).
Run {.help [{.fun assert_forecast}](scoringutils::assert_forecast)}
to confirm. To get rid of this warning entirely,
call `as.data.table()` on the forecast object."
)
#nolint end
)
}
}
Expand All @@ -323,7 +317,7 @@
if (inherits(validation, "try-error")) {
cli_warn(
c(
"!" = "Error in validating forecast object: {validation}"
`!` = "Error in validating forecast object: {validation}"
)
)
}
Expand All @@ -346,7 +340,7 @@
if (inherits(validation, "try-error")) {
cli_warn(
c(
"!" = "Error in validating forecast object: {validation}"
`!` = "Error in validating forecast object: {validation}"
)
)
}
Expand All @@ -369,7 +363,7 @@
if (inherits(validation, "try-error")) {
cli_warn(
c(
"!" = "Error in validating forecast object: {validation}"
`!` = "Error in validating forecast object: {validation}"
)
)
}
Expand Down Expand Up @@ -428,7 +422,7 @@
if (inherits(forecast_type, "try-error")) {
cli_inform(
c(
"!" = "Could not determine forecast type due to error in validation." #nolint
`!` = "Could not determine forecast type due to error in validation."
)
)
} else {
Expand All @@ -443,7 +437,7 @@
if (inherits(forecast_unit, "try-error")) {
cli_inform(
c(
"!" = "Could not determine forecast unit." #nolint
`!` = "Could not determine forecast unit."
)
)
} else {
Expand Down
12 changes: 5 additions & 7 deletions R/class-scores.R
Original file line number Diff line number Diff line change
Expand Up @@ -114,25 +114,23 @@
assert_data_frame(x)
metrics <- attr(x, "metrics")
if (error && is.null(metrics)) {
#nolint start: keyword_quote_linter
cli_abort(
c(
"!" = "Input needs an attribute `metrics` with the names of the
`!` = "Input needs an attribute `metrics` with the names of the
scoring rules that were used for scoring.",
"i" = "See `?get_metrics` for further information."
`i` = "See `?get_metrics` for further information."

Check warning on line 121 in R/class-scores.R

View workflow job for this annotation

GitHub Actions / lint-changed-files

file=R/class-scores.R,line=121,col=9,[keyword_quote_linter] Only quote named arguments to functions if necessary, i.e., if the name is not a valid R symbol (see ?make.names).
)
)
#nolint end
}

if (!all(metrics %in% names(x))) {
#nolint start: keyword_quote_linter object_usage_linter
#nolint start: object_usage_linter
missing <- setdiff(metrics, names(x))
cli_warn(
c(
"!" = "The following scores have been previously computed, but are no
`!` = "The following scores have been previously computed, but are no
longer column names of the data: {.val {missing}}",
"i" = "See {.code ?get_metrics} for further information."
`i` = "See {.code ?get_metrics} for further information."
)
)
#nolint end
Expand Down
4 changes: 1 addition & 3 deletions R/get-correlations.R
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,12 @@
# check correlations is actually a matrix of correlations
col_present <- check_columns_present(correlations, "metric")
if (any(lower_triangle > 1, na.rm = TRUE) || !isTRUE(col_present)) {
#nolint start: keyword_quote_linter
cli_abort(
c(
"Found correlations > 1 or missing `metric` column.",
"i" = "Did you forget to call {.fn scoringutils::get_correlations}?"
`i` = "Did you forget to call {.fn scoringutils::get_correlations}?"

Check warning on line 93 in R/get-correlations.R

View workflow job for this annotation

GitHub Actions / lint-changed-files

file=R/get-correlations.R,line=93,col=9,[keyword_quote_linter] Only quote named arguments to functions if necessary, i.e., if the name is not a valid R symbol (see ?make.names).
)
)
#nolint end
}

rownames(lower_triangle) <- colnames(lower_triangle)
Expand Down
6 changes: 3 additions & 3 deletions R/get-forecast-type.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ assert_forecast_type <- function(data,
desired = NULL) {
assert_character(desired, null.ok = TRUE)
if (!is.null(desired) && desired != actual) {
#nolint start: object_usage_linter keyword_quote_linter
#nolint start: object_usage_linter
cli_abort(
c(
"!" = "Forecast type determined by scoringutils based on input:
`!` = "Forecast type determined by scoringutils based on input:
{.val {actual}}.",
"i" = "Desired forecast type: {.val {desired}}."
`i` = "Desired forecast type: {.val {desired}}."
)
)
#nolint end
Expand Down
2 changes: 1 addition & 1 deletion R/get-pit-histogram.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,6 @@ get_pit_histogram <- function(forecast, num_bins, breaks, by,
#' @export
get_pit_histogram.default <- function(forecast, num_bins, breaks, by, ...) {
cli_abort(c(
"!" = "The input needs to be a valid forecast object represented as quantiles or samples." # nolint
`!` = "The input needs to be a valid forecast object represented as quantiles or samples."
))
}
2 changes: 0 additions & 2 deletions R/helper-quantile-interval-range.R
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,10 @@
if (length(unique(forecast$boundary)) < 2) {
cli_abort(
c(
#nolint start: keyword_quote_linter
`!` = "No valid forecast intervals found.",
`i` = "A forecast interval comprises two

Check warning on line 86 in R/helper-quantile-interval-range.R

View workflow job for this annotation

GitHub Actions / lint-changed-files

file=R/helper-quantile-interval-range.R,line=86,col=9,[keyword_quote_linter] Only quote named arguments to functions if necessary, i.e., if the name is not a valid R symbol (see ?make.names).
quantiles with quantile levels symmetric around the median
(e.g. 0.25 and 0.75)"
#nolint end
)
)
}
Expand Down
8 changes: 3 additions & 5 deletions R/metrics-interval-range.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,23 @@
if (any(diff < 0)) {
cli_abort(
c(
"!" = "All values in `upper` need to be greater than or equal to
`!` = "All values in `upper` need to be greater than or equal to
the corresponding values in `lower`"
)
)
}
if (any(interval_range > 0 & interval_range < 1, na.rm = TRUE)) {
#nolint start: keyword_quote_linter
cli_warn(
c(
"!" = "Found interval ranges between 0 and 1. Are you sure that's
`!` = "Found interval ranges between 0 and 1. Are you sure that's
right? An interval range of 0.5 e.g. implies a (49.75%, 50.25%)
prediction interval.",
"i" = "If you want to score a (25%, 75%) prediction interval, set
`i` = "If you want to score a (25%, 75%) prediction interval, set

Check warning on line 46 in R/metrics-interval-range.R

View workflow job for this annotation

GitHub Actions / lint-changed-files

file=R/metrics-interval-range.R,line=46,col=9,[keyword_quote_linter] Only quote named arguments to functions if necessary, i.e., if the name is not a valid R symbol (see ?make.names).
`interval_range = 50`."
),
.frequency = "once",
.frequency_id = "small_interval_range"
)
#nolint end
}
return(invisible(NULL))
}
Expand Down
2 changes: 1 addition & 1 deletion R/metrics-nominal.R
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ assert_input_categorical <- function(
# Allow for numeric errors
invalid_rows <- abs(summed_predictions - 1) > 1e-4
if (any(invalid_rows)) {
#nolint start: keyword_quote_linter object_usage_linter
#nolint start: object_usage_linter
row_indices <- which(invalid_rows)
cli_abort(
c(
Expand Down
6 changes: 3 additions & 3 deletions R/metrics-point.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ assert_dims_ok_point <- function(observed, predicted) {
n_pred <- length(as.vector(predicted))
# check that both are either of length 1 or of equal length
if ((n_obs != 1) && (n_pred != 1) && (n_obs != n_pred)) {
#nolint start: keyword_quote_linter object_usage_linter
#nolint start: object_usage_linter
cli_abort(
c(
"!" = "`observed` and `predicted` must either be of length 1 or
`!` = "`observed` and `predicted` must either be of length 1 or
of equal length.",
"i" = "Found {n_obs} and {n_pred}."
`i` = "Found {n_obs} and {n_pred}."
)
)
#nolint end
Expand Down
20 changes: 7 additions & 13 deletions R/metrics-quantile.R
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,11 @@
complete_intervals <-
duplicated(interval_ranges) | duplicated(interval_ranges, fromLast = TRUE)
if (!all(complete_intervals) && !isTRUE(na.rm)) {
#nolint start: keyword_quote_linter object_usage_linter
#nolint start: object_usage_linter
incomplete <- quantile_level[quantile_level != 0.5][!complete_intervals]
cli_abort(
c(
"!" = "Not all quantile levels specified form symmetric prediction
`!` = "Not all quantile levels specified form symmetric prediction
intervals.
The following quantile levels miss a corresponding lower/upper bound:
{.val {incomplete}}.
Expand Down Expand Up @@ -347,10 +347,10 @@
100 - (100 - interval_range) / 2
) / 100
if (!all(necessary_quantiles %in% quantile_level)) {
#nolint start: keyword_quote_linter object_usage_linter
#nolint start: object_usage_linter
cli_abort(
c(
"!" = "To compute the interval coverage for an interval range of
`!` = "To compute the interval coverage for an interval range of
{.val {interval_range}%}, the {.val {necessary_quantiles}} quantiles
are required"
)
Expand Down Expand Up @@ -442,14 +442,12 @@
dim(predicted) <- c(n, N)
}
if (!(0.5 %in% quantile_level)) {
#nolint start: keyword_quote_linter
cli_inform(
c(
"i" = "Median not available, interpolating median from the two
`i` = "Median not available, interpolating median from the two

Check warning on line 447 in R/metrics-quantile.R

View workflow job for this annotation

GitHub Actions / lint-changed-files

file=R/metrics-quantile.R,line=447,col=9,[keyword_quote_linter] Only quote named arguments to functions if necessary, i.e., if the name is not a valid R symbol (see ?make.names).
innermost quantiles in order to compute bias."
)
)
#nolint end
}
bias <- sapply(1:n, function(i) {
bias_quantile_single_vector(
Expand Down Expand Up @@ -493,14 +491,12 @@
order <- order(quantile_level)
predicted <- predicted[order]
if (!all(diff(predicted) >= 0)) {
#nolint start: keyword_quote_linter
cli_abort(
c(
"!" = "Predictions must not be decreasing with increasing
`!` = "Predictions must not be decreasing with increasing
quantile level."
)
)
#nolint end
}

median_prediction <- interpolate_median(predicted, quantile_level)
Expand Down Expand Up @@ -581,14 +577,12 @@
ae_median_quantile <- function(observed, predicted, quantile_level) {
assert_input_quantile(observed, predicted, quantile_level)
if (!any(quantile_level == 0.5)) {
#nolint start: keyword_quote_linter
cli_abort(
c(
"!" = "In order to compute the absolute error of the median,
`!` = "In order to compute the absolute error of the median,
{.val 0.5} must be among the quantiles given"
)
)
#nolint end
}
if (is.null(dim(predicted))) {
predicted <- matrix(predicted, nrow = 1)
Expand Down
Loading
Loading