logfunctions: Signal Event to Log File Handlers.

Description Usage Arguments Details Using log functions in pipeline expressions Examples

Description

Create and signal an DEBUG, INFO, WARN, ERROR or CRITICAL condition. The appropriate condition handlers listening for the type of event signalled will be notified. The message can be wrapped in a one sided formula, in which case string interpolation will be used.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11

Arguments

message

character: the message to log.

...

additional data to log (ignored by default formatter)

.level

character the logging level.

Details

The function log_with_level is not intended for direct use. Rather the other functions redirect to this function with the appropriate level set.

Using log functions in pipeline expressions

It is possible to use logging as part of a pipeline by specifying the message as a two-sided formula with the dot placeholder as left-hand side, i.e. . ~ message. In this case the value can be referenced in string interpolations as '.'. Since the piped object is placed as the first argument, the message is now technically the first element in ... and is identified if this is a formula in the appropriate form.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
log_file("console")
log_info("Basic information.")

dollars <- 10
log_info(~ "I have ${dollars} dollars.")

## Not run: 
library(magrittr)
log_file("console")

iris_sub <-
  iris %>%
  subset(Species == "versicolor") %>%
  log_info(. ~ "Keeping ${NROW(.)} versicolor rows.") %>%
  transform(Ratio = Sepal.Length/Sepal.Width)

## End(Not run)

smbache/loggr documentation built on May 30, 2019, 5:02 a.m.