Learn R Programming

purrr (version 1.0.2)

quietly: Wrap a function to capture side-effects

Description

Create a modified version of .f that captures side-effects along with the return value of the function and returns a list containing the result, output, messages and warnings.

Usage

quietly(.f)

Value

A function that takes the same arguments as .f, but returns a different value, as described above.

Arguments

.f

A function to modify, specified in one of the following ways:

  • A named function, e.g. mean.

  • An anonymous function, e.g. \(x) x + 1 or function(x) x + 1.

  • A formula, e.g. ~ .x + 1. Only recommended if you require backward compatibility with older versions of R.

Adverbs

This function is called an adverb because it modifies the effect of a function (a verb). If you'd like to include a function created an adverb in a package, be sure to read faq-adverbs-export.

See Also

Other adverbs: auto_browse(), compose(), insistently(), negate(), partial(), possibly(), safely(), slowly()

Examples

Run this code
f <- function() {
  print("Hi!")
  message("Hello")
  warning("How are ya?")
  "Gidday"
}
f()

f_quiet <- quietly(f)
str(f_quiet())

Run the code above in your browser using DataLab