signal | R Documentation |
Similar to usethis::ui_*()
function suite but does not require
importing the usethis, crayon, or cli packages.
All signal_*()
functions can be silenced by
setting options(signal.quiet = TRUE)
.
value(x) signal_done(...) signal_todo(...) signal_oops(...) signal_info(...) signal_rule(text = "", line_col = NULL, lty = c("single", "double")) add_color(x, col) add_style ## S3 method for class 'soma_style' print(x, ...) ## S3 method for class 'soma_style' x$y has_style(x) rm_style(x)
x |
Character. A string to report to the UI or to add a style/color. |
... |
Elements passed directly to |
text |
Character. String of length 1. Added at the left margin of the horizontal rule. |
line_col |
See |
lty |
Character. Either "single" or "double" line type (matched). |
col |
Color (or style) for the text (or line). Currently one of:
|
y |
A coloring function, i.e. an element the |
value
: Signal a value to the UI. Similar to
usethis::ui_value()
.
Each element of x
becomes an entry in a comma separated list
and a blue
color is added.
signal_done
: Signal a completed task to the UI. Similar to
usethis::ui_done()
.
signal_todo
: Signal a to-do task to the UI. Similar to
usethis::ui_todo()
.
signal_oops
: Signal oops error to the UI. Similar to
usethis::ui_oops()
.
signal_info
: Signal info to the UI. Similar to
usethis::ui_info()
.
signal_rule
: Make a rule with left aligned text. Similar to
cli::rule()
.
add_color
: Add a color or style to a string. Similar to
crayon::crayon()
.
add_style
: An alternative syntax. A list object where each
element is a color/style function wrapping around add_color()
and
each element determines the col
argument. See examples.
print.soma_style
: Functions in the apply_style
object have their
own class, which allows for the special S3 print method and the chaining
in the examples below.
$.soma_style
: Easily chain styles with $
S3 method.
has_style
: Logical. Test if string contains ANSI styles/colors.
rm_style
: Remove a color or style from character strings.
n <- 4 cat("You need this many bikes:", value(n + 1)) # value() collapses lengths by sep = ", " value(names(mtcars)) # signal_done() signal_done("Tests have passed!") # easily construct complex messages signal_done("The 'LETTERS' vector has", value(length(LETTERS)), "elements") # add a horizontal rule writeLines(signal_rule()) writeLines(signal_rule("Header", line_col = "green", lty = "double")) cat(add_color("Hello world!", "blue")) # Combined with signal_*() functions signal_oops("You shall", add_color("not", "red"), "pass!") # colors and styles available via add_style() add_style # These are equivalent cat(add_style$blue("Hello world!")) cat(add_color("Hello world!", "blue")) # Combine styles red <- add_style$red("This is red") string <- c(red, "and this is not") cat(string) # Combine styles blue <- add_style$blue("blue") red <- add_style$red("red") string <- add_style$bold(c(blue, red, "nothing")) cat(string) # chain styles via `$` cat(add_style$bold("Success")) cat(add_style$bold$green("Success")) cat(add_style$bold$green$italic("Success")) cat(add_style$bold$green$italic$red("Success")) # potential typos are trapped ## Not run: cat(add_style$bold$greeen$italic("Success")) ## End(Not run) # check for ANSI styling has_style(add_style$green("Hello world!")) has_style(add_style$italic("Hello world!")) # remove ANSI styling cat(rm_style(add_style$green("Hello world!"))) cat(rm_style(add_style$italic$cyan("Hello world!")))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.