In Python, you can specify string formats by name (this is of course a silly example):
parameters = {'label':'months', 'april':4,'may':5,'june':6}
formatstring = '%(label)s: %(april)d %(may)d %(june)d'
outputstring = formatstring % parameters
(The formatstring % parameters
notation is the Python equivalent to do.call(sprintf,c(formatstring,as.list(parameters)))
in R.)
The output string would be "months: 4, 5, 6
". parameters is stored as a key-value pair (which might be called a dictionary, hashtable, or named list in various languages). The string format %(text)s
allows you to reference which dictionary item (text
) should be formatted in that slot.
Is there anything equivalent in R, or you have you found a good workaround?