dedent | R Documentation |
Remove the common leading whitespace from each line. This is useful in multi-line strings to make them line up with the left edge of the display, while still presenting them in indented form within the source code.
dedent(x, strip = TRUE)
x |
character vector. The strings from which to remove common leading whitespace. |
strip |
logical. Should the leading and trailing whitespace line be
removed from each element of |
strip
is TRUE
by default because the standard use case is to
dedent a multi-line string that appears in the source code. Refer to section
Examples.
Tabs and spaces are both whitespace, but they are not treated equally. This is because tab is a different width depending on the context.
character vector, the same length as x
, and with the dim
,
dimnames
, and names
attributes of x
(after possible
coercion to character).
cat(dedent("
here is a multi-line string that appears in the source code. we wish to
remove the common indent from each line, and dedent should do this for us!
---- hopefully this works ----
"), sep = "\n")
# for me, a tab prints as eight spaces when preceded by a newline
# but since tab isn't always eight spaces, we treat this as unsolveable :(
# there is no common leading whitespace since " " != "\t"
cat(dedent("
another multi-line string, this time with no common leading whitespace
\tanother multi-line string, this time with no common leading whitespace
"), sep = "\n")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.