Skip to content

Commit

Permalink
register teal.logger handlers (#628)
Browse files Browse the repository at this point in the history
close insightsengineering/coredev-tasks#502
test with insightsengineering/teal.logger#73

As a bonus, we can safely move `logger` to suggests (it's still used in
tests)

---------

Signed-off-by: Pawel Rucki <[email protected]>
  • Loading branch information
pawelru authored Mar 20, 2024
1 parent 1fc1653 commit 2892295
Show file tree
Hide file tree
Showing 19 changed files with 20 additions and 65 deletions.
8 changes: 4 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ Imports:
DT (>= 0.13),
forcats (>= 1.0.0),
grid,
logger (>= 0.2.0),
scales,
shinyjs,
shinyTree (>= 0.2.8),
Expand All @@ -45,7 +44,7 @@ Imports:
stringr (>= 1.4.1),
teal.code (>= 0.5.0),
teal.data (>= 0.5.0),
teal.logger (>= 0.1.1),
teal.logger (>= 0.1.3.9013),
teal.reporter (>= 0.3.0),
teal.widgets (>= 0.4.0),
tern (>= 0.9.3),
Expand All @@ -66,6 +65,7 @@ Suggests:
jsonlite,
knitr (>= 1.42),
lattice (>= 0.18-4),
logger (>= 0.2.0),
MASS,
nestcolor (>= 0.1.0),
rlang (>= 1.0.0),
Expand All @@ -78,7 +78,7 @@ VignetteBuilder:
Config/Needs/verdepcheck: haleyjeppson/ggmosaic, tidyverse/ggplot2,
rstudio/shiny, insightsengineering/teal,
insightsengineering/teal.transform, mllg/checkmate, tidyverse/dplyr,
rstudio/DT, tidyverse/forcats, daroczig/logger, r-lib/scales,
rstudio/DT, tidyverse/forcats, r-lib/scales,
daattali/shinyjs, shinyTree/shinyTree, rstudio/shinyvalidate,
dreamRs/shinyWidgets, tidyverse/stringr,
insightsengineering/teal.code, insightsengineering/teal.data,
Expand All @@ -87,7 +87,7 @@ Config/Needs/verdepcheck: haleyjeppson/ggmosaic, tidyverse/ggplot2,
tidyverse/tibble, tidyverse/tidyr, tidymodels/broom,
daattali/colourpicker, daattali/ggExtra, aphalo/ggpmisc, aphalo/ggpp,
slowkow/ggrepel, baddstats/goftest, gridExtra, ramnathv/htmlwidgets,
jeroen/jsonlite, yihui/knitr, deepayan/lattice, MASS,
jeroen/jsonlite, yihui/knitr, deepayan/lattice, daroczig/logger, MASS,
insightsengineering/nestcolor, r-lib/rlang,
insightsengineering/rtables, sparkline, insightsengineering/teal.data,
r-lib/testthat, r-lib/withr
Expand Down
2 changes: 1 addition & 1 deletion R/tm_a_pca.R
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ tm_a_pca <- function(label = "Principal Component Analysis",
size = c(2, 1, 8),
pre_output = NULL,
post_output = NULL) {
logger::log_info("Initializing tm_a_pca")
message("Initializing tm_a_pca")

# Normalize the parameters
if (inherits(dat, "data_extract_spec")) dat <- list(dat)
Expand Down
2 changes: 1 addition & 1 deletion R/tm_a_regression.R
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ tm_a_regression <- function(label = "Regression Analysis",
default_plot_type = 1,
default_outlier_label = "USUBJID",
label_segment_threshold = c(0.5, 0, 10)) {
logger::log_info("Initializing tm_a_regression")
message("Initializing tm_a_regression")

# Normalize the parameters
if (inherits(regressor, "data_extract_spec")) regressor <- list(regressor)
Expand Down
2 changes: 1 addition & 1 deletion R/tm_data_table.R
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ tm_data_table <- function(label = "Data Table",
server_rendering = FALSE,
pre_output = NULL,
post_output = NULL) {
logger::log_info("Initializing tm_data_table")
message("Initializing tm_data_table")

# Start of assertions
checkmate::assert_string(label)
Expand Down
2 changes: 1 addition & 1 deletion R/tm_file_viewer.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
#'
tm_file_viewer <- function(label = "File Viewer Module",
input_path = list("Current Working Directory" = ".")) {
logger::log_info("Initializing tm_file_viewer")
message("Initializing tm_file_viewer")

# Normalize the parameters
if (length(label) == 0 || identical(label, "")) label <- " "
Expand Down
2 changes: 1 addition & 1 deletion R/tm_front_page.R
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ tm_front_page <- function(label = "Front page",
additional_tags = tagList(),
footnotes = character(0),
show_metadata = FALSE) {
logger::log_info("Initializing tm_front_page")
message("Initializing tm_front_page")

# Start of assertions
checkmate::assert_string(label)
Expand Down
2 changes: 1 addition & 1 deletion R/tm_g_association.R
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ tm_g_association <- function(label = "Association",
pre_output = NULL,
post_output = NULL,
ggplot2_args = teal.widgets::ggplot2_args()) {
logger::log_info("Initializing tm_g_association")
message("Initializing tm_g_association")

# Normalize the parameters
if (inherits(ref, "data_extract_spec")) ref <- list(ref)
Expand Down
2 changes: 1 addition & 1 deletion R/tm_g_bivariate.R
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ tm_g_bivariate <- function(label = "Bivariate Plots",
ggplot2_args = teal.widgets::ggplot2_args(),
pre_output = NULL,
post_output = NULL) {
logger::log_info("Initializing tm_g_bivariate")
message("Initializing tm_g_bivariate")

# Normalize the parameters
if (inherits(x, "data_extract_spec")) x <- list(x)
Expand Down
2 changes: 1 addition & 1 deletion R/tm_g_distribution.R
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ tm_g_distribution <- function(label = "Distribution Module",
plot_width = NULL,
pre_output = NULL,
post_output = NULL) {
logger::log_info("Initializing tm_g_distribution")
message("Initializing tm_g_distribution")

# Requires Suggested packages
extra_packages <- c("ggpmisc", "ggpp", "goftest", "MASS", "broom")
Expand Down
2 changes: 1 addition & 1 deletion R/tm_g_response.R
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ tm_g_response <- function(label = "Response Plot",
ggplot2_args = teal.widgets::ggplot2_args(),
pre_output = NULL,
post_output = NULL) {
logger::log_info("Initializing tm_g_response")
message("Initializing tm_g_response")

# Normalize the parameters
if (inherits(response, "data_extract_spec")) response <- list(response)
Expand Down
2 changes: 1 addition & 1 deletion R/tm_g_scatterplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ tm_g_scatterplot <- function(label = "Scatterplot",
post_output = NULL,
table_dec = 4,
ggplot2_args = teal.widgets::ggplot2_args()) {
logger::log_info("Initializing tm_g_scatterplot")
message("Initializing tm_g_scatterplot")

# Requires Suggested packages
extra_packages <- c("ggpmisc", "ggExtra", "colourpicker")
Expand Down
2 changes: 1 addition & 1 deletion R/tm_g_scatterplotmatrix.R
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ tm_g_scatterplotmatrix <- function(label = "Scatterplot Matrix",
plot_width = NULL,
pre_output = NULL,
post_output = NULL) {
logger::log_info("Initializing tm_g_scatterplotmatrix")
message("Initializing tm_g_scatterplotmatrix")

# Requires Suggested packages
if (!requireNamespace("lattice", quietly = TRUE)) {
Expand Down
2 changes: 1 addition & 1 deletion R/tm_missing_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ tm_missing_data <- function(label = "Missing data",
),
pre_output = NULL,
post_output = NULL) {
logger::log_info("Initializing tm_missing_data")
message("Initializing tm_missing_data")

# Requires Suggested packages
if (!requireNamespace("gridExtra", quietly = TRUE)) {
Expand Down
2 changes: 1 addition & 1 deletion R/tm_outliers.R
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ tm_outliers <- function(label = "Outliers Module",
plot_width = NULL,
pre_output = NULL,
post_output = NULL) {
logger::log_info("Initializing tm_outliers")
message("Initializing tm_outliers")

# Normalize the parameters
if (inherits(outlier_var, "data_extract_spec")) outlier_var <- list(outlier_var)
Expand Down
2 changes: 1 addition & 1 deletion R/tm_t_crosstable.R
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ tm_t_crosstable <- function(label = "Cross Table",
pre_output = NULL,
post_output = NULL,
basic_table_args = teal.widgets::basic_table_args()) {
logger::log_info("Initializing tm_t_crosstable")
message("Initializing tm_t_crosstable")

# Requires Suggested packages
if (!requireNamespace("rtables", quietly = TRUE)) {
Expand Down
2 changes: 1 addition & 1 deletion R/tm_variable_browser.R
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ tm_variable_browser <- function(label = "Variable Browser",
pre_output = NULL,
post_output = NULL,
ggplot2_args = teal.widgets::ggplot2_args()) {
logger::log_info("Initializing tm_variable_browser")
message("Initializing tm_variable_browser")

# Requires Suggested packages
if (!requireNamespace("sparkline", quietly = TRUE)) {
Expand Down
1 change: 1 addition & 0 deletions R/zzz.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.onLoad <- function(libname, pkgname) {
teal.logger::register_logger(namespace = "teal.modules.general")
teal.logger::register_handlers("teal.modules.general")
}

### global variables
Expand Down
10 changes: 0 additions & 10 deletions tests/testthat/helper-functions.R
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
local_logger_threshold <- function(threshold, envir = parent.frame()) {
old <- logger::log_threshold(namespace = "teal.modules.general")

# Equivalent to withr::defer
thunk <- as.call(list(function() logger::log_threshold(old, namespace = "teal.modules.general")))
do.call(base::on.exit, list(thunk, TRUE, FALSE), envir = envir)
logger::log_threshold(threshold, namespace = "teal.modules.general")
invisible(old)
}

# Create a mock data extact spec for tests
mock_data_extract_spec <- function(dataname = "MOCK_DATASET",
select_choices = sample(LETTERS, sample(2:10, 1)),
Expand Down
36 changes: 0 additions & 36 deletions tests/testthat/test-tm_g_bivariate.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
testthat::test_that("tm_g_bivariate creates a `teal_module` object", {
local_logger_threshold(logger::FATAL) # Suppress logger messages

testthat::expect_s3_class(
tm_g_bivariate(
"a label",
Expand All @@ -23,8 +21,6 @@ testthat::test_that("tm_g_bivariate creates a `teal_module` object", {
})

testthat::test_that("tm_g_bivariate creates a `teal_module` object with default options", {
local_logger_threshold(logger::FATAL) # Suppress logger messages

testthat::expect_s3_class(
tm_g_bivariate(
"a label",
Expand All @@ -36,8 +32,6 @@ testthat::test_that("tm_g_bivariate creates a `teal_module` object with default
})

testthat::test_that("tm_g_bivariate creates a `teal_module` object with multiple data extract specs", {
local_logger_threshold(logger::FATAL) # Suppress logger messages

testthat::expect_s3_class(
tm_g_bivariate(
"a label",
Expand All @@ -51,8 +45,6 @@ testthat::test_that("tm_g_bivariate creates a `teal_module` object with multiple
})

testthat::test_that("tm_g_bivariate creates a module with datanames taken from data extracts", {
local_logger_threshold(logger::FATAL) # Suppress logger messages

mod <- tm_g_bivariate(
"a label",
list(
Expand All @@ -71,8 +63,6 @@ testthat::test_that("tm_g_bivariate creates a module with datanames taken from d
# Test `x` and `y` arguments with invalid data_extract_spec

testthat::test_that("tm_g_bivariate fails when `x` contains a spec with multiple selection", {
local_logger_threshold(logger::FATAL) # Suppress logger messages

testthat::expect_error(
tm_g_bivariate(
"a label",
Expand All @@ -86,8 +76,6 @@ testthat::test_that("tm_g_bivariate fails when `x` contains a spec with multiple
})

testthat::test_that("tm_g_bivariate fails when `x` contains multiple spec with (at least one ) multiple selection", {
local_logger_threshold(logger::FATAL) # Suppress logger messages

testthat::expect_error(
tm_g_bivariate(
"a label",
Expand All @@ -102,8 +90,6 @@ testthat::test_that("tm_g_bivariate fails when `x` contains multiple spec with (
})

testthat::test_that("tm_g_bivariate fails when `x` contains multiple spec with (at least one ) multiple selection", {
local_logger_threshold(logger::FATAL) # Suppress logger messages

testthat::expect_error(
tm_g_bivariate(
"a label",
Expand All @@ -118,8 +104,6 @@ testthat::test_that("tm_g_bivariate fails when `x` contains multiple spec with (
})

testthat::test_that("tm_g_bivariate fails when `y` contains multiple spec with (at least one ) multiple selection", {
local_logger_threshold(logger::FATAL) # Suppress logger messages

testthat::expect_error(
tm_g_bivariate(
"a label",
Expand All @@ -136,8 +120,6 @@ testthat::test_that("tm_g_bivariate fails when `y` contains multiple spec with (
# Test `plot_height` and `plot_width` arguments

testthat::test_that("tm_g_bivariate fails when `plot_height` is not valid", {
local_logger_threshold(logger::FATAL) # Suppress logger messages

testthat::expect_error(
tm_g_bivariate(
"a label",
Expand All @@ -150,8 +132,6 @@ testthat::test_that("tm_g_bivariate fails when `plot_height` is not valid", {
})

testthat::test_that("tm_g_bivariate fails when `plot_height` is not valid", {
local_logger_threshold(logger::FATAL) # Suppress logger messages

testthat::expect_error(
tm_g_bivariate(
"a label",
Expand All @@ -164,8 +144,6 @@ testthat::test_that("tm_g_bivariate fails when `plot_height` is not valid", {
})

testthat::test_that("tm_g_bivariate fails when `plot_height` is not valid", {
local_logger_threshold(logger::FATAL) # Suppress logger messages

testthat::expect_error(
tm_g_bivariate(
"a label",
Expand All @@ -178,8 +156,6 @@ testthat::test_that("tm_g_bivariate fails when `plot_height` is not valid", {
})

testthat::test_that("tm_g_bivariate fails when `plot_width` is not valid", {
local_logger_threshold(logger::FATAL) # Suppress logger messages

testthat::expect_error(
tm_g_bivariate(
"a label",
Expand All @@ -192,8 +168,6 @@ testthat::test_that("tm_g_bivariate fails when `plot_width` is not valid", {
})

testthat::test_that("tm_g_bivariate fails when `plot_width` is not valid", {
local_logger_threshold(logger::FATAL) # Suppress logger messages

testthat::expect_error(
tm_g_bivariate(
"a label",
Expand All @@ -206,8 +180,6 @@ testthat::test_that("tm_g_bivariate fails when `plot_width` is not valid", {
})

testthat::test_that("tm_g_bivariate fails when `plot_width` is not valid", {
local_logger_threshold(logger::FATAL) # Suppress logger messages

testthat::expect_error(
tm_g_bivariate(
"a label",
Expand All @@ -222,8 +194,6 @@ testthat::test_that("tm_g_bivariate fails when `plot_width` is not valid", {
# Test `color_settings` argument

testthat::test_that("tm_g_bivariate fails when `color_setting` is FALSE and `color` is supplied", {
local_logger_threshold(logger::FATAL) # Suppress logger messages

testthat::expect_error(
tm_g_bivariate(
"a label",
Expand All @@ -237,8 +207,6 @@ testthat::test_that("tm_g_bivariate fails when `color_setting` is FALSE and `col
})

testthat::test_that("tm_g_bivariate fails when `color_setting` is FALSE and `size` is supplied", {
local_logger_threshold(logger::FATAL) # Suppress logger messages

testthat::expect_error(
tm_g_bivariate(
"a label",
Expand All @@ -252,8 +220,6 @@ testthat::test_that("tm_g_bivariate fails when `color_setting` is FALSE and `siz
})

testthat::test_that("tm_g_bivariate fails when `color_setting` is FALSE and `fill` is supplied", {
local_logger_threshold(logger::FATAL) # Suppress logger messages

testthat::expect_error(
tm_g_bivariate(
"a label",
Expand All @@ -267,8 +233,6 @@ testthat::test_that("tm_g_bivariate fails when `color_setting` is FALSE and `fil
})

testthat::test_that("tm_g_bivariate determines `color`, `size` and `fill` when `color_setting` is TRUE", {
local_logger_threshold(logger::FATAL) # Suppress logger messages

mod <- tm_g_bivariate(
"a label",
mock_data_extract_spec(select_multiple = FALSE),
Expand Down

0 comments on commit 2892295

Please sign in to comment.