Skip to content

Commit

Permalink
suppress package startup messages in tests
Browse files Browse the repository at this point in the history
using:

```
r_files <- list.files(path = "tests/testthat", pattern = "\\.R$", full.names = TRUE)

process_file <- function(file_path) {
  lines <- readLines(file_path)

  modified_lines <- sapply(lines, function(line) {
    if (grepl("^\\s*library\\(", line)) {
      pkg <- gsub("library(", "", line, fixed = TRUE)
      pkg <- gsub(")", "", pkg, fixed = TRUE)
      if (pkg %in% c("modeltests", tidyverse::tidyverse_packages(), tidymodels::tidymodels_packages())) {
        return(line)
      }
      return(paste0("suppressPackageStartupMessages(", line, ")"))
    } else {
      return(line)
    }
  })

  writeLines(modified_lines, file_path)
}

lapply(r_files, process_file)
``
  • Loading branch information
simonpcouch committed Oct 21, 2024
1 parent 7128251 commit 2c32738
Show file tree
Hide file tree
Showing 59 changed files with 67 additions and 67 deletions.
2 changes: 1 addition & 1 deletion tests/testthat/test-aer.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ skip_if_not_installed("modeltests")
library(modeltests)

skip_if_not_installed("AER")
library(AER)
suppressPackageStartupMessages(library(AER))
library(dplyr)
library(modeltests)

Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-betareg.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ library(modeltests)

skip_if_not_installed("betareg")

library(betareg)
suppressPackageStartupMessages(library(betareg))
data("GasolineYield")

fit1 <- betareg(yield ~ batch + temp, data = GasolineYield)
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-biglm.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ skip_if_not_installed("modeltests")
library(modeltests)

skip_if_not_installed("biglm")
library(biglm)
suppressPackageStartupMessages(library(biglm))

fit <- biglm(mpg ~ wt + disp, mtcars)
fit2 <- bigglm(am ~ mpg, mtcars, family = binomial())
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-bingroup.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ skip_if_not_installed("modeltests")
library(modeltests)

skip_if_not_installed("binGroup")
library(binGroup)
suppressPackageStartupMessages(library(binGroup))

bw <- binWidth(100, .1)
bd <- binDesign(nmax = 300, delta = 0.06, p.hyp = 0.1, power = .8)
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-boot.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ skip_if_not_installed("modeltests")
library(modeltests)

skip_if_not_installed("boot")
library(boot)
suppressPackageStartupMessages(library(boot))

test_that("boot tidier arguments", {
check_arguments(tidy.boot)
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-car.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ skip_if_not_installed("modeltests")
library(modeltests)

skip_if_not_installed("survival")
library(survival)
suppressPackageStartupMessages(library(survival))

skip_if_not_installed("car")

Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-cluster.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ skip_if_not_installed("modeltests")
library(modeltests)

skip_if_not_installed("cluster")
library(cluster)
suppressPackageStartupMessages(library(cluster))

skip_if_not_installed("modeldata")
library(modeldata)
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-cmprsk.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ skip_if_not_installed("modeltests")
library(modeltests)

skip_if_not_installed("cmprsk")
library(cmprsk)
suppressPackageStartupMessages(library(cmprsk))
set.seed(2)

# simulate data
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-drc.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ skip_if_not_installed("modeltests")
library(modeltests)

skip_if_not_installed("drc")
library(drc)
suppressPackageStartupMessages(library(drc))

mod <- drm(dead / total ~ conc, type,
weights = total, data = selenium, fct = LL.2(), type = "binomial"
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-emmeans.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ skip_if_not_installed("modeltests")
library(modeltests)

skip_if_not_installed("lsmeans")
library(lsmeans)
suppressPackageStartupMessages(library(lsmeans))

skip_if_not_installed("lme4")
library(lme4)
suppressPackageStartupMessages(library(lme4))

fit <- lm(sales1 ~ price1 + price2 + day + store, data = oranges)
rg <- ref.grid(fit)
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-epiR.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ rownames(dat) <- c("DF+", "DF-")
colnames(dat) <- c("FUS+", "FUS-")

skip_if_not_installed("MASS")
library(MASS)
suppressPackageStartupMessages(library(MASS))
birthwt <- MASS::birthwt

birthwt$low <- factor(birthwt$low, levels = c(1, 0))
Expand All @@ -18,7 +18,7 @@ tab2 <- table(birthwt$smoke, birthwt$low, birthwt$race,
dnn = c("Smoke", "Low BW", "Race")
)

library(epiR)
suppressPackageStartupMessages(library(epiR))
fit1 <- epi.2by2(
dat = as.table(dat), method = "cross.sectional",
conf.level = 0.95, units = 100, outcome = "as.columns"
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-ergm.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ skip_if_not_installed("modeltests")
library(modeltests)

skip_if_not_installed("ergm")
library(ergm)
suppressPackageStartupMessages(library(ergm))

data(florentine)
data(faux.mesa.high)
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-geepack.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ skip_if_not_installed("modeltests")
library(modeltests)

skip_if_not_installed("geepack")
library(geepack)
suppressPackageStartupMessages(library(geepack))

dat <- data.frame(state.region, state.x77)

Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-glmnet.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ skip_if_not_installed("modeltests")
library(modeltests)

skip_if_not_installed("glmnet")
library(glmnet)
suppressPackageStartupMessages(library(glmnet))

set.seed(27)

Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-glmnetUtils.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ skip_if_not_installed("modeltests")
library(modeltests)

skip_if_not_installed("glmnetUtils")
library(glmnetUtils)
suppressPackageStartupMessages(library(glmnetUtils))

set.seed(27)

Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-gmm.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ skip_if_not_installed("modeltests")
library(modeltests)

skip_if_not_installed("gmm")
library(gmm)
suppressPackageStartupMessages(library(gmm))

data(Finance)

Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-joineRML.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ skip_if_not_installed("modeltests")
library(modeltests)

skip_if_not_installed("joineRML")
library(joineRML)
suppressPackageStartupMessages(library(joineRML))

# NOTE: the models used in these tests are created in
# `data-raw/fit_and_save_long_running_models.R`, and then are saved to
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-kendall.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ skip_if_not_installed("modeltests")
library(modeltests)

skip_if_not_installed("Kendall")
library(Kendall)
suppressPackageStartupMessages(library(Kendall))

a <- c(2.5, 2.5, 2.5, 2.5, 5, 6.5, 6.5, 10, 10, 10, 10, 10, 14, 14, 14, 16, 17)
b <- c(1, 1, 1, 1, 2, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 2, 2)
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-lavaan.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ skip_if_not_installed("modeltests")
library(modeltests)

skip_if_not_installed("lavaan")
library(lavaan)
suppressPackageStartupMessages(library(lavaan))

fit <- sem("mpg ~ wt", data = mtcars)
form <- paste("F =~", paste0("x", 1:9, collapse = " + "))
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-lmbeta-lm-beta.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ skip_if_not_installed("modeltests")
library(modeltests)

skip_if_not_installed("lm.beta")
library(lm.beta)
suppressPackageStartupMessages(library(lm.beta))

test_that("lm.beta tidier arguments", {
check_arguments(tidy.lm.beta)
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-lmodel2.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ skip_if_not_installed("modeltests")
library(modeltests)

skip_if_not_installed("lmodel2")
library(lmodel2)
suppressPackageStartupMessages(library(lmodel2))

data("mod2ex2")
fit <- lmodel2(Prey ~ Predators, data = mod2ex2, "relative", "relative", 99)
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-lmtest.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ skip_if_not_installed("modeltests")
library(modeltests)

skip_if_not_installed("lmtest")
library(lmtest)
suppressPackageStartupMessages(library(lmtest))

skip_if_not_installed("sandwich")
library(sandwich)
suppressPackageStartupMessages(library(sandwich))

m <- lm(dist ~ speed, data = cars)
ct <- lmtest::coeftest(m)
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-margins.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ skip_if_not_installed("modeltests")
library(modeltests)

skip_if_not_installed("margins")
library(margins)
suppressPackageStartupMessages(library(margins))

fit1 <- glm(am ~ cyl + hp + wt, data = mtcars, family = binomial)
marg1 <- margins(fit1)
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-mass-negbin.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ skip_if_not_installed("modeltests")
library(modeltests)

skip_if_not_installed("MASS")
library(MASS)
suppressPackageStartupMessages(library(MASS))

fit <- glm.nb(Days ~ Sex / (Age + Eth * Lrn), data = MASS::quine)

Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-mass-polr.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ skip_if_not_installed("modeltests")
library(modeltests)

skip_if_not_installed("MASS")
library(MASS)
suppressPackageStartupMessages(library(MASS))

fit <- polr(
Sat ~ Infl + Type + Cont,
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-mass-rlm.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ skip_if_not_installed("modeltests")
library(modeltests)

skip_if_not_installed("MASS")
library(MASS)
suppressPackageStartupMessages(library(MASS))

fit <- rlm(stack.loss ~ ., stackloss)

Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-mclust.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ skip_if_not_installed("modeltests")
library(modeltests)

skip_if_not_installed("mclust")
library(mclust)
suppressPackageStartupMessages(library(mclust))

skip_if_not_installed("modeldata")
library(modeldata)
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-mediation.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ skip_if_not_installed("modeltests")
library(modeltests)

skip_if_not_installed("mediation")
library(mediation)
suppressPackageStartupMessages(library(mediation))

data(jobs)
b <- lm(job_seek ~ treat + econ_hard + sex + age, data = jobs)
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-metafor.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ skip_if_not_installed("modeltests")
library(modeltests)

skip_if_not_installed("metafor")
library(metafor)
suppressPackageStartupMessages(library(metafor))

skip_if_not_installed("lme4")
library(lme4)
suppressPackageStartupMessages(library(lme4))

# check arguments ---------------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-mfx.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ skip_if_not_installed("modeltests")
library(modeltests)

skip_if_not_installed("mfx")
library(mfx)
suppressPackageStartupMessages(library(mfx))

# simulate data
set.seed(12345)
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-mlogit.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ library(modeltests)

skip_if_not_installed("mlogit")
skip_if_not_installed("AER")
library(mlogit)
library(AER)
suppressPackageStartupMessages(library(mlogit))
suppressPackageStartupMessages(library(AER))
library(dplyr)

data("Fishing", package = "mlogit")
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-muhaz.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ library(modeltests)
skip_if_not_installed("muhaz")
skip_if_not_installed("survival") # does this skip with base R?

library(muhaz)
suppressPackageStartupMessages(library(muhaz))

# load the ovarian data
data(cancer, package = "survival")
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-multcomp.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ skip_if_not_installed("modeltests")
library(modeltests)

skip_if_not_installed("multcomp")
library(multcomp)
suppressPackageStartupMessages(library(multcomp))

amod <- aov(breaks ~ wool + tension, data = warpbreaks)
wht <- glht(amod, linfct = mcp(tension = "Tukey"))
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-nnet.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ skip_if_not_installed("modeltests")
library(modeltests)

skip_if_not_installed("nnet")
library(nnet)
suppressPackageStartupMessages(library(nnet))

fit <- multinom(gear ~ mpg + factor(am), data = mtcars, trace = FALSE)

Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-ordinal.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ skip_if_not_installed("modeltests")
library(modeltests)

skip_if_not_installed("ordinal")
library(ordinal)
suppressPackageStartupMessages(library(ordinal))

fit <- clm(rating ~ temp * contact, data = wine)

Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-plm.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ skip_if_not_installed("modeltests")
library(modeltests)

skip_if_not_installed("plm")
library(plm)
suppressPackageStartupMessages(library(plm))

data(Produc, package = "plm")
fit <- plm(
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-polca.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ library(modeltests)

skip_if_not_installed("poLCA")
skip_if_not_installed("MASS")
library(poLCA)
suppressPackageStartupMessages(library(poLCA))

data(values)
fit <- poLCA(cbind(A, B, C, D) ~ 1, values, nclass = 2, verbose = FALSE)
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-quantreg-nlrq.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ skip_if_not_installed("modeltests")
library(modeltests)

skip_if_not_installed("quantreg")
library(quantreg)
suppressPackageStartupMessages(library(quantreg))

set.seed(27)

Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-quantreg-rq.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ skip_if_not_installed("modeltests")
library(modeltests)

skip_if_not_installed("quantreg")
library(quantreg)
suppressPackageStartupMessages(library(quantreg))

data(stackloss)

Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-quantreg-rqs.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ skip_if_not_installed("modeltests")
library(modeltests)

skip_if_not_installed("quantreg")
library(quantreg)
suppressPackageStartupMessages(library(quantreg))

airquality <- na.omit(airquality)

Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-robust.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ skip_if_not_installed("modeltests")
library(modeltests)

skip_if_not_installed("robust")
library(robust)
suppressPackageStartupMessages(library(robust))

fit <- lmRob(mpg ~ wt, data = mtcars)
fit2 <- glmRob(am ~ wt, data = mtcars, family = "binomial")
Expand Down
Loading

0 comments on commit 2c32738

Please sign in to comment.