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
.
Value
A function that takes the same arguments as .f
, but returns
a different value, as described above.
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
f <- function() {
print("Hi!")
message("Hello")
warning("How are ya?")
"Gidday"
}
f()
#> [1] "Hi!"
#> Hello
#> Warning: How are ya?
#> [1] "Gidday"
f_quiet <- quietly(f)
str(f_quiet())
#> List of 4
#> $ result : chr "Gidday"
#> $ output : chr "[1] \"Hi!\""
#> $ warnings: chr "How are ya?"
#> $ messages: chr "Hello\n"