Learn R Programming

GetoptLong (version 1.0.5)

qqcat: Print a string which has been intepolated with variables

Description

Print a string which has been intepolated with variables

Usage

qqcat(..., envir = parent.frame(), code.pattern = NULL, file = "",
    sep = " ", fill = FALSE, labels = NULL, append = FALSE, cat_prefix = NULL,
    strwrap = qq.options("cat_strwrap"), strwrap_param = list(), sep2 = "")

Arguments

...

text string in which variables are marked with certain rules

envir

environment where to look for those variables

code.pattern

pattern of marks for the variables

file

pass to cat

sep

pass to cat

fill

pass to cat

labels

pass to cat

append

pass to cat

cat_prefix

prefix string. It is prior than qq.options(cat_prefix).

strwrap

whether call strwrap to wrap the string

strwrap_param

parameters sent to strwrap, must be a list

sep2

Separation character when there are multiple templates.

Details

This function is a shortcut of

    cat(qq(text, envir, code.pattern), ...)  

Additionally, you can add global prefix:

    qq.options("cat_prefix" = "[INFO] ")
    qq.options("cat_prefix" = function(x) format(Sys.time(), "[%Y-%m-%d %H:%M:%S] "))
    qq.options("cat_prefix" = NULL)  

You can also add local prefix by specifying cat_prefix in qqcat.

    qqcat(text, cat_prefix = "[INFO] ")  

Please refer to qq to find more details.

Examples

Run this code
# NOT RUN {
a = 1
b = "text"
qqcat("a = @{a}, b = '@{b}'\n")
qqcat("a = `a`, b = '`b`'\n", code.pattern = "`CODE`")

qq.options("cat_prefix" = function(x) format(Sys.time(), "[%Y-%m-%d %H:%M:%S] "))
qqcat("a = @{a}, b = '@{b}'\n")
Sys.sleep(2)
qqcat("a = @{a}, b = '@{b}'\n")
qq.options(RESET = TRUE)
# }

Run the code above in your browser using DataLab