psprintf: Paste together sprintf-style text and variable values

View source: R/psprintf.R

psprintfR Documentation

Paste together sprintf-style text and variable values

Description

Helper function to sprintf a bunch of key-value (string-variableVector) pairs, then paste them together with a good separator for contructing remake recipes.

Usage

psprintf(..., sep = "\n      ")

Arguments

...

arguments that are either (1) character strings to insert directly into the output or (2) named arguments, where the name is an sprintf pattern and the value is a list or vector of variables to apply to that particular sprintf pattern. After any relevant sprint evaluation, all arguments will be pasted, with the specified separator, in order to create a single character output.

sep

separator for the list of arguments, defaults to new line

Examples

cat(psprintf(
  "plot_frame(",
  "png_file = target_name,",
  "date = date_%s," = "2018-01-23",
  "state = %s)" = "Wisconsin"))

##plot_frame(
##     png_file = target_name,
##     date = date_2018-01-23,
##     state = Wisconsin)

cat(psprintf(
  'cmd(',
  'a = %s, b = \'%s\','=c('dog','cat'),
  'c = "rat")'
))
## cmd(
##      a = dog, b = 'cat',
##      c = "rat")

cat(psprintf(
  'cmd(',
  'a = %s, b = %0.1f,'=list('dog',7),
  'c = "rat")'
))
## cmd(
##     a = dog, b = 7.0,
##     c = "rat")

USGS-R/scipiper documentation built on May 25, 2023, 8:47 a.m.