diff --git a/.Rbuildignore b/.Rbuildignore index 6cc6c4991..ebdc8b742 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -17,3 +17,4 @@ ^\.devcontainer$ ^CODE_OF_CONDUCT\.md$ ^inst/manuscript/output$ +^CRAN-SUBMISSION$ diff --git a/R/avail_forecasts.R b/R/avail_forecasts.R index 7f183e2aa..5fd6160f8 100644 --- a/R/avail_forecasts.R +++ b/R/avail_forecasts.R @@ -27,7 +27,9 @@ #' @export #' @keywords check-forecasts #' @examples -#' data.table::setDTthreads(1) # only needed to avoid issues on CRAN +#' \dontshow{ +#' data.table::setDTthreads(2) # restricts number of cores used on CRAN +#' } #' #' avail_forecasts(example_quantile, #' collapse = c("quantile"), diff --git a/R/pairwise-comparisons.R b/R/pairwise-comparisons.R index efce335eb..f18be4831 100644 --- a/R/pairwise-comparisons.R +++ b/R/pairwise-comparisons.R @@ -52,7 +52,9 @@ #' @author Johannes Bracher, \email{johannes.bracher@@kit.edu} #' @keywords scoring #' @examples -#' data.table::setDTthreads(1) # only needed to avoid issues on CRAN +#' \dontshow{ +#' data.table::setDTthreads(2) # restricts number of cores used on CRAN +#' } #' #' scores <- score(example_quantile) #' pairwise <- pairwise_comparison(scores, by = "target_type") @@ -227,8 +229,8 @@ pairwise_comparison_one_group <- function(scores, # make result character instead of factor result[, `:=`( - "model" = as.character(model), - "compare_against" = as.character(compare_against) + model = as.character(model), + compare_against = as.character(compare_against) )] # calculate relative skill as geometric mean diff --git a/R/pit.R b/R/pit.R index fa91dc82d..de5361bfa 100644 --- a/R/pit.R +++ b/R/pit.R @@ -62,7 +62,9 @@ #' @seealso [pit()] #' @importFrom stats runif #' @examples -#' data.table::setDTthreads(1) # only needed to avoid issues on CRAN +#' \dontshow{ +#' data.table::setDTthreads(2) # restricts number of cores used on CRAN +#' } #' #' ## continuous predictions #' true_values <- rnorm(20, mean = 1:20) @@ -125,10 +127,10 @@ pit_sample <- function(true_values, # check data type ------------------------------------------------------------ # check whether continuous or integer - if (!isTRUE(all.equal(as.vector(predictions), as.integer(predictions)))) { - continuous_predictions <- TRUE - } else { + if (isTRUE(all.equal(as.vector(predictions), as.integer(predictions)))) { continuous_predictions <- FALSE + } else { + continuous_predictions <- TRUE } # calculate PIT-values ------------------------------------------------------- @@ -217,7 +219,7 @@ pit <- function(data, value.var = "prediction" ) - pit <- data_wide[, .("pit_value" = pit_sample( + pit <- data_wide[, .(pit_value = pit_sample( true_values = true_value, predictions = as.matrix(.SD) )), diff --git a/R/plot.R b/R/plot.R index 8af22d507..0aa7d4185 100644 --- a/R/plot.R +++ b/R/plot.R @@ -24,7 +24,9 @@ #' @examples #' library(ggplot2) #' library(magrittr) # pipe operator -#' data.table::setDTthreads(1) # only needed to avoid issues on CRAN +#' \dontshow{ +#' data.table::setDTthreads(2) # restricts number of cores used on CRAN +#' } #' #' scores <- score(example_quantile) %>% #' summarise_scores(by = c("model", "target_type")) %>% @@ -470,7 +472,7 @@ plot_predictions <- function(data, # it separately here to deal with the case when only the median is provided # (in which case ggdist::geom_lineribbon() will fail) if (0 %in% range) { - select_median <- (forecasts$range %in% 0 & forecasts$boundary == "lower") + select_median <- (forecasts$range == 0 & forecasts$boundary == "lower") median <- forecasts[select_median] if (nrow(median) > 0) { @@ -582,7 +584,9 @@ make_na <- make_NA #' @importFrom data.table dcast #' @export #' @examples -#' data.table::setDTthreads(1) # only needed to avoid issues on CRAN +#' \dontshow{ +#' data.table::setDTthreads(2) # restricts number of cores used on CRAN +#' } #' scores <- score(example_quantile) #' scores <- summarise_scores(scores, by = c("model", "range")) #' plot_interval_coverage(scores) @@ -835,7 +839,9 @@ plot_pairwise_comparison <- function(comparison_result, #' @importFrom stats density #' @return vector with the scoring values #' @examples -#' data.table::setDTthreads(1) # only needed to avoid issues on CRAN +#' \dontshow{ +#' data.table::setDTthreads(2) # restricts number of cores used on CRAN +#' } #' #' # PIT histogram in vector based format #' true_values <- rnorm(30, mean = 1:30) diff --git a/R/score.R b/R/score.R index ba7dcb913..0b653a8f4 100644 --- a/R/score.R +++ b/R/score.R @@ -75,7 +75,9 @@ #' #' @examples #' library(magrittr) # pipe operator -#' data.table::setDTthreads(1) # only needed to avoid issues on CRAN +#' \dontshow{ +#' data.table::setDTthreads(2) # restricts number of cores used on CRAN +#' } #' #' check_forecasts(example_quantile) #' score(example_quantile) %>% diff --git a/R/summarise_scores.R b/R/summarise_scores.R index 5283a8061..11fda06a6 100644 --- a/R/summarise_scores.R +++ b/R/summarise_scores.R @@ -42,7 +42,9 @@ #' provided to `fun`. For more information see the documentation of the #' respective function. #' @examples -#' data.table::setDTthreads(1) # only needed to avoid issues on CRAN +#' \dontshow{ +#' data.table::setDTthreads(2) # restricts number of cores used on CRAN +#' } #' library(magrittr) # pipe operator #' #' scores <- score(example_continuous) @@ -279,6 +281,9 @@ check_summary_params <- function(scores, #' summary is present according to the value specified in `by`. #' @examples #' library(magrittr) # pipe operator +#' \dontshow{ +#' data.table::setDTthreads(2) # restricts number of cores used on CRAN +#' } #' score(example_quantile) %>% #' add_coverage(by = c("model", "target_type")) %>% #' summarise_scores(by = c("model", "target_type")) %>% diff --git a/man/add_coverage.Rd b/man/add_coverage.Rd index ad658432e..56f2a2e3f 100644 --- a/man/add_coverage.Rd +++ b/man/add_coverage.Rd @@ -33,6 +33,9 @@ the unit of a single forecast. } \examples{ library(magrittr) # pipe operator +\dontshow{ + data.table::setDTthreads(2) # restricts number of cores used on CRAN +} score(example_quantile) \%>\% add_coverage(by = c("model", "target_type")) \%>\% summarise_scores(by = c("model", "target_type")) \%>\% diff --git a/man/avail_forecasts.Rd b/man/avail_forecasts.Rd index 5eef64b30..60fed26fb 100644 --- a/man/avail_forecasts.Rd +++ b/man/avail_forecasts.Rd @@ -57,7 +57,9 @@ number of forecasts per model and location). This is useful to determine whether there are any missing forecasts. } \examples{ -data.table::setDTthreads(1) # only needed to avoid issues on CRAN +\dontshow{ + data.table::setDTthreads(2) # restricts number of cores used on CRAN +} avail_forecasts(example_quantile, collapse = c("quantile"), diff --git a/man/pairwise_comparison.Rd b/man/pairwise_comparison.Rd index 4c14b975e..d45442b7e 100644 --- a/man/pairwise_comparison.Rd +++ b/man/pairwise_comparison.Rd @@ -64,7 +64,9 @@ The implementation of the permutation test follows the function Andrea Riebler and Michaela Paul. } \examples{ -data.table::setDTthreads(1) # only needed to avoid issues on CRAN +\dontshow{ + data.table::setDTthreads(2) # restricts number of cores used on CRAN +} scores <- score(example_quantile) pairwise <- pairwise_comparison(scores, by = "target_type") diff --git a/man/pit_sample.Rd b/man/pit_sample.Rd index 8e896ce8f..335b66574 100644 --- a/man/pit_sample.Rd +++ b/man/pit_sample.Rd @@ -76,7 +76,9 @@ In this context it should be noted, though, that uniformity of the PIT is a necessary but not sufficient condition of calibration. } \examples{ -data.table::setDTthreads(1) # only needed to avoid issues on CRAN +\dontshow{ + data.table::setDTthreads(2) # restricts number of cores used on CRAN +} ## continuous predictions true_values <- rnorm(20, mean = 1:20) diff --git a/man/plot_interval_coverage.Rd b/man/plot_interval_coverage.Rd index 9c7da16fe..8c95634ac 100644 --- a/man/plot_interval_coverage.Rd +++ b/man/plot_interval_coverage.Rd @@ -21,7 +21,9 @@ ggplot object with a plot of interval coverage Plot interval coverage } \examples{ -data.table::setDTthreads(1) # only needed to avoid issues on CRAN +\dontshow{ + data.table::setDTthreads(2) # restricts number of cores used on CRAN +} scores <- score(example_quantile) scores <- summarise_scores(scores, by = c("model", "range")) plot_interval_coverage(scores) diff --git a/man/plot_pit.Rd b/man/plot_pit.Rd index d0eceabd3..af95f421a 100644 --- a/man/plot_pit.Rd +++ b/man/plot_pit.Rd @@ -32,7 +32,9 @@ Make a simple histogram of the probability integral transformed values to visually check whether a uniform distribution seems likely. } \examples{ -data.table::setDTthreads(1) # only needed to avoid issues on CRAN +\dontshow{ + data.table::setDTthreads(2) # restricts number of cores used on CRAN +} # PIT histogram in vector based format true_values <- rnorm(30, mean = 1:30) diff --git a/man/plot_score_table.Rd b/man/plot_score_table.Rd index 9984e8000..acf07cd7b 100644 --- a/man/plot_score_table.Rd +++ b/man/plot_score_table.Rd @@ -31,7 +31,9 @@ Plots a coloured table of summarised scores obtained using \examples{ library(ggplot2) library(magrittr) # pipe operator -data.table::setDTthreads(1) # only needed to avoid issues on CRAN +\dontshow{ + data.table::setDTthreads(2) # restricts number of cores used on CRAN +} scores <- score(example_quantile) \%>\% summarise_scores(by = c("model", "target_type")) \%>\% diff --git a/man/score.Rd b/man/score.Rd index 2cbeed348..4804efcd0 100644 --- a/man/score.Rd +++ b/man/score.Rd @@ -81,7 +81,9 @@ as well as the paper \href{https://arxiv.org/abs/2205.07090}{Evaluating Forecast } \examples{ library(magrittr) # pipe operator -data.table::setDTthreads(1) # only needed to avoid issues on CRAN +\dontshow{ + data.table::setDTthreads(2) # restricts number of cores used on CRAN +} check_forecasts(example_quantile) score(example_quantile) \%>\% diff --git a/man/summarise_scores.Rd b/man/summarise_scores.Rd index ed63cf1af..d41d5a6ae 100644 --- a/man/summarise_scores.Rd +++ b/man/summarise_scores.Rd @@ -81,7 +81,9 @@ respective function.} Summarise scores as produced by \code{\link[=score]{score()}} } \examples{ -data.table::setDTthreads(1) # only needed to avoid issues on CRAN +\dontshow{ + data.table::setDTthreads(2) # restricts number of cores used on CRAN +} library(magrittr) # pipe operator scores <- score(example_continuous) diff --git a/tests/testthat/setup.R b/tests/testthat/setup.R index 5f2b22a2c..11342633b 100644 --- a/tests/testthat/setup.R +++ b/tests/testthat/setup.R @@ -1,6 +1,7 @@ # load common required test packages library(ggplot2, quietly = TRUE) suppressMessages(library(magrittr)) +data.table::setDTthreads(2) # restricts number of cores used on CRAN # compute quantile scores -scores <- suppressMessages(score(example_quantile)) \ No newline at end of file +scores <- suppressMessages(score(example_quantile)) diff --git a/vignettes/scoringutils.Rmd b/vignettes/scoringutils.Rmd index 72d1f159f..022e0a2ad 100644 --- a/vignettes/scoringutils.Rmd +++ b/vignettes/scoringutils.Rmd @@ -19,6 +19,8 @@ library(magrittr) library(data.table) library(ggplot2) library(knitr) +# number of threads used for data.table computations, update as needed +data.table::setDTthreads(2) ``` The `scoringutils` package provides a collection of metrics and proper scoring rules that make it simple to score probabilistic forecasts against the true observed values. You can find more information in the paper [Evaluating Forecasts with scoringutils in R](https://arxiv.org/abs/2205.07090) as well as the [Metrics-Vignette](https://epiforecasts.io/scoringutils/articles/metric-details.html) and the [Scoring forecasts directly Vignette](https://epiforecasts.io/scoringutils/articles/scoring-forecasts-directly.html). @@ -35,7 +37,7 @@ Most of the time, the `score()` function will be able to do the entire evaluatio ```{r, echo=FALSE} requirements <- data.table( - "Format" = c( + Format = c( "quantile-based", "sample-based", "binary", "pairwise-comparisons" ), `Required columns` = c(