From 7f6ac55ae22137d286883115814be71abc86115c Mon Sep 17 00:00:00 2001 From: Sebastian Funk Date: Fri, 2 Feb 2024 13:51:22 +0000 Subject: [PATCH] updates in response to lintr --- .github/workflows/lint-only-changed-files.yaml | 1 + R/estimate_infections.R | 8 ++++---- R/extract.R | 2 +- R/opts.R | 12 +++++------- R/stan.R | 2 +- 5 files changed, 12 insertions(+), 13 deletions(-) diff --git a/.github/workflows/lint-only-changed-files.yaml b/.github/workflows/lint-only-changed-files.yaml index 8af5572bc..605b2db69 100644 --- a/.github/workflows/lint-only-changed-files.yaml +++ b/.github/workflows/lint-only-changed-files.yaml @@ -23,6 +23,7 @@ jobs: with: dependencies: NA extra-packages: | + stan-dev/cmdstanr any::gh any::lintr any::purrr diff --git a/R/estimate_infections.R b/R/estimate_infections.R index 52c376a62..2a2c68020 100644 --- a/R/estimate_infections.R +++ b/R/estimate_infections.R @@ -333,7 +333,7 @@ init_cumulative_fit <- function(args, samples = 50, warmup = 50, open_progress = FALSE, show_messages = FALSE ), - data = args$data, init = args$init, + data = args$data, init = args$init ) # change observations to be cumulative in order to protect against noise and # give an approximate fit (though for Rt constrained to be > 1) @@ -450,10 +450,10 @@ fit_model_with_nuts <- function(args, future = FALSE, max_execution_time = Inf, ) } - if (!inherits(fit, c("stanfit", "CmdStanMCMC"))) { - return(NULL) - } else { + if (inherits(fit, c("stanfit", "CmdStanMCMC"))) { return(fit) + } else { + return(NULL) } } diff --git a/R/extract.R b/R/extract.R index 2c1d2ad9c..d4b7fbc33 100644 --- a/R/extract.R +++ b/R/extract.R @@ -102,7 +102,7 @@ extract_samples <- function(stan_fit, pars = NULL, include = TRUE) { ) df <- df[, new_draw := permutation[.draw]] setkey(df, new_draw) - max_indices <- strsplit(tail(df$index, 1), split = ",")[[1]] + max_indices <- strsplit(tail(df$index, 1), split = ",", fixed = TRUE)[[1]] if (any(grepl("[^0-9]", max_indices))) { max_indices <- 1 } else { diff --git a/R/opts.R b/R/opts.R index 7d79c50ca..9ad675dff 100644 --- a/R/opts.R +++ b/R/opts.R @@ -791,13 +791,11 @@ stan_opts <- function(object = NULL, ...) { method <- arg_match(method, values = c("sampling", "vb")) backend <- arg_match(backend, values = c("rstan", "cmdstanr")) - if (backend == "cmdstanr") { - if (!requireNamespace("cmdstanr", quietly = TRUE)) { - stop(paste0( - "The `cmdstanr` package needs to be installed for using the ", - "\"cmdstanr\" backend." - )) - } + if (backend == "cmdstanr" && !requireNamespace("cmdstanr", quietly = TRUE)) { + stop( + "The `cmdstanr` package needs to be installed for using the ", + "\"cmdstanr\" backend." + ) } opts <- list() if (!is.null(object) && !missing(backend)) { diff --git a/R/stan.R b/R/stan.R index 7db30a692..102b265ae 100644 --- a/R/stan.R +++ b/R/stan.R @@ -35,7 +35,7 @@ package_model <- function(model = "estimate_infections", ) if (verbose) { message(sprintf("Using model %s.", model)) - message(sprintf("include is %s.", paste(include, collapse = ", "))) + message(sprintf("include is %s.", toString(include))) } monitor <- suppressMessages