Skip to content

Commit

Permalink
Merge pull request #514 from epiforecasts/fix-cran
Browse files Browse the repository at this point in the history
Issue 486: Fix NOTEs for CRAN submission
  • Loading branch information
nikosbosse authored Nov 29, 2023
2 parents 3db7de1 + e17be30 commit 413d427
Show file tree
Hide file tree
Showing 18 changed files with 67 additions and 25 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@
^\.devcontainer$
^CODE_OF_CONDUCT\.md$
^inst/manuscript/output$
^CRAN-SUBMISSION$
4 changes: 3 additions & 1 deletion R/avail_forecasts.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
8 changes: 5 additions & 3 deletions R/pairwise-comparisons.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand Down
12 changes: 7 additions & 5 deletions R/pit.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 -------------------------------------------------------
Expand Down Expand Up @@ -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)
)),
Expand Down
14 changes: 10 additions & 4 deletions R/plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")) %>%
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion R/score.R
Original file line number Diff line number Diff line change
Expand Up @@ -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) %>%
Expand Down
7 changes: 6 additions & 1 deletion R/summarise_scores.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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")) %>%
Expand Down
3 changes: 3 additions & 0 deletions man/add_coverage.Rd

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

4 changes: 3 additions & 1 deletion man/avail_forecasts.Rd

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

4 changes: 3 additions & 1 deletion man/pairwise_comparison.Rd

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

4 changes: 3 additions & 1 deletion man/pit_sample.Rd

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

4 changes: 3 additions & 1 deletion man/plot_interval_coverage.Rd

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

4 changes: 3 additions & 1 deletion man/plot_pit.Rd

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

4 changes: 3 additions & 1 deletion man/plot_score_table.Rd

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

4 changes: 3 additions & 1 deletion man/score.Rd

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

4 changes: 3 additions & 1 deletion man/summarise_scores.Rd

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

3 changes: 2 additions & 1 deletion tests/testthat/setup.R
Original file line number Diff line number Diff line change
@@ -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))
scores <- suppressMessages(score(example_quantile))
4 changes: 3 additions & 1 deletion vignettes/scoringutils.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand All @@ -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(
Expand Down

0 comments on commit 413d427

Please sign in to comment.