messagef: Chainable, Sprintf-able messages

Description Usage Arguments Details See Also Examples

View source: R/messagef.R

Description

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.

Usage

1
messagef(x, fmt, domain = NULL, appendLF = TRUE)

Arguments

x

r data object (vector or data.frame)

fmt

a vector that includes all the parts that are passed to sprintf; See Details below.

domain

carried over from base R message(); see ?base::message

appendLF

carried over from base R message(); see ?base::message

Details

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.

See Also

message sprintf

Examples

 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
## Not run: 
  messagef("this isn't right") # wrong, fmt argument not named

## End(Not run)
# 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)
  )

## End(Not run)
#

Paul-James/pjames documentation built on Aug. 9, 2019, 12:18 p.m.