printf: A fancy print function

Description Usage Arguments Details Examples

View source: R/printf.R

Description

printf() is reminiscent of python's f-strings, where prefacing a string with f enables the user to evaluate code within braces before printing to the console. This functionality already exists in the glue package; so this is wrapper around that. However, what it also brings is an additional wrapper around the crayon package at the same time. You can therefore colour and evaluate print statements easily.

Usage

1
printf(string)

Arguments

string

String to format.

Details

How to use printf

In short, use $$ to signal a call to the crayon library. Calls can be nested with further single $ symbols. Close the call with $$x (Optional for the final closing brace).

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
var1 <- 1
var2 <- 2
var3 <- "world"
var4 <- "this example"


printf("{var1} added to {var2} equals {var1 + var2}")
printf("Hello $$strikethrough mum $$x world!")
printf("$$blue this example shows that `printf()` will auto close final braces")
printf("This example shows that you can $$cyan$bold combine $$x formating")
printf("$$magenta$italic {var4} $$x $$green$underline brings it $$x $$blurred all together")

datr-studio/commonr documentation built on Jan. 17, 2022, 12:26 a.m.