Portmanteau of message
and sprintf
. Pass messages to the output console while in the middle of some serious data pipelines. If used ina pipeline, returns the original data object invisibly. This allows for use inside or outside of pipelines. Also wraps sprintf() to allow quick parameterized messages even when not used in a pipeline.
messagef(x, fmt, domain = NULL, appendLF = TRUE)
x | r data object (vector or data.frame) |
---|---|
fmt | a vector that includes all the parts that are passed to |
domain | carried over from base R |
appendLF | carried over from base R |
Since this is able to take in a data object and pass it along (as in a pipeline), the first argument is the data argument and it's almost never intended to be named.
The fmt
parameter was kind of hacked out to allow use of this message function with a single text string in and out of a pipeline and multiple inputs for sprintf
in and out of a pipeline. It's a vector of inputs that gets converted to the lowest common class (generally character
). Because of this the fmt parameter always needs to be named when not used within a pipeline. For example, you can't just type: messagef('this is a message')
because the first argument is the data argument (which passes through silently if used in a pipeline) and the second argument is fmt. The correct use is: messagef(fmt = 'this is a message')
.
This can be used just like base::message
, but if taking advantage of a sprintf
like use case, the 1st value in the fmt
vector is passed as the fmt
parameter for sprintf
, while all following values are supplied to sprintf
's ...
parameter.
See ?base::sprintf
for details on the limits and possibilities for inputs into the fmt
parameter.
message sprintf
# NOT RUN { messagef("this isn't right") # wrong, fmt argument not named # }# 1 messagef(fmt = "this is right") # correct, fmt argument has to be named here#># 2# NOT RUN { iris %>% messagef( c('this makes %s a %s %s bruv', 809, 'jargon', 'tester') ) %>% group_by( Species ) %>% messagef( 'all done bruv' ) %>% summarise( sum = sum(Petal.Width) ) # }#