Skip to content

Commit f49c50a

Browse files
author
Stefan Fleck
committed
Adds assert_namespace calls to Appender initializers where appropriate;
skip print.Appender*() tests if not all required packages are available
1 parent bf64ad7 commit f49c50a

File tree

4 files changed

+18
-1
lines changed

4 files changed

+18
-1
lines changed

DESCRIPTION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ Suggests:
4040
rotor (>= 0.2.2),
4141
RPostgres,
4242
rprojroot,
43+
RPushbullet,
4344
RSQLite,
4445
sendmailR,
4546
testthat,

NEWS.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
## new features
44
* added `logger_tree()` which provides an overview of all registered loggers
55
* added `print()` and `format()` methods for Appenders
6-
* `AppenderMemory`: added `data` and `dt` active fields
6+
* `AppenderMemory`: added `data` and `dt` active fields (which return the
7+
log as a data.frame or data.table)
78

89
## API changes
910
* Removed deprecated functions `FATAL()`, `ERROR()`. Use `lgr$fatal()`,

R/Appender.R

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,8 @@ AppenderJson <- R6::R6Class(
419419
layout = LayoutJson$new(),
420420
filters = NULL
421421
){
422+
assert_namespace("jsonlite")
423+
422424
self$set_file(file)
423425
self$set_threshold(threshold)
424426
self$set_layout(layout)
@@ -655,6 +657,7 @@ AppenderDt <- R6::R6Class(
655657
buffer_size = 1e5,
656658
filters = NULL
657659
){
660+
assert_namespace("data.table")
658661
assert(is_scalar_integerish(buffer_size))
659662
assert(
660663
data.table::is.data.table(prototype) && is.integer(prototype$.id),
@@ -1948,6 +1951,8 @@ AppenderPushbullet <- R6::R6Class(
19481951
apikey = NULL,
19491952
filters = NULL
19501953
){
1954+
assert_namespace("RPushbullet")
1955+
19511956
private$initialize_buffer(buffer_size)
19521957
self$set_flush_on_rotate(FALSE)
19531958
self$set_flush_on_exit(FALSE)

tests/testthat/test_print_Appender.R

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@ context("print_Appender")
44

55

66
test_that("all Appenders print() without failure", {
7+
if (
8+
!requireNamespace("sendmailR") ||
9+
!requireNamespace("RPushbullet") ||
10+
!requireNamespace("rotor") ||
11+
!requireNamespace("DBI") ||
12+
!requireNamespace("RSQLite")
13+
){
14+
skip("Required packages not installed")
15+
}
16+
717
tf <- tempfile()
818
on.exit(unlink(tf))
919

0 commit comments

Comments
 (0)