File: log_eval.Rd

package info (click to toggle)
r-cran-logger 0.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,324 kB
  • sloc: sh: 13; makefile: 2
file content (55 lines) | stat: -rw-r--r-- 1,641 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/helpers.R
\name{log_eval}
\alias{log_eval}
\title{Evaluate an expression and log results}
\usage{
log_eval(expr, level = TRACE, multiline = FALSE)
}
\arguments{
\item{expr}{R expression to be evaluated while logging the
expression itself along with the result}

\item{level}{\code{\link[=log_levels]{log_levels()}}}

\item{multiline}{setting to \code{FALSE} will print both the expression
(enforced to be on one line by removing line-breaks if any) and
its result on a single line separated by \verb{=>}, while setting to
\code{TRUE} will log the expression and the result in separate
sections reserving line-breaks and rendering the printed results}
}
\description{
Evaluate an expression and log results
}
\examples{
\dontshow{old <- logger:::namespaces_set()}
log_eval(pi * 2, level = INFO)

## lowering the log level threshold so that we don't have to set a higher level in log_eval
log_threshold(TRACE)
log_eval(x <- 4)
log_eval(sqrt(x))

## log_eval can be called in-line as well as returning the return value of the expression
x <- log_eval(mean(runif(1e3)))
x

## https://twitter.com/krlmlr/status/1067864829547999232
f <- sqrt
g <- mean
x <- 1:31
log_eval(f(g(x)), level = INFO)
log_eval(y <- f(g(x)), level = INFO)

## returning a function
log_eval(f <- sqrt)
log_eval(f)

## evaluating something returning a wall of "text"
log_eval(f <- log_eval)
log_eval(f <- log_eval, multiline = TRUE)

## doing something computationally intensive
log_eval(system.time(for (i in 1:100) mad(runif(1000))), multiline = TRUE)
\dontshow{logger:::namespaces_set(old)}
}