EVOLUTION-MANAGER
Edit File: cli_format.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Format a value for printing</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for cli_format {cli}"><tr><td>cli_format {cli}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Format a value for printing</h2> <h3>Description</h3> <p>This function can be used directly, or via the <code style="white-space: pre;">{.val ...}</code> inline style. <code style="white-space: pre;">{.val {expr}}</code> calls <code>cli_format()</code> automatically on the value of <code>expr</code>, before styling and collapsing it. </p> <h3>Usage</h3> <pre> cli_format(x, style = NULL, ...) ## Default S3 method: cli_format(x, style = NULL, ...) ## S3 method for class 'character' cli_format(x, style = NULL, ...) ## S3 method for class 'numeric' cli_format(x, style = NULL, ...) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>x</code></td> <td> <p>The object to format.</p> </td></tr> <tr valign="top"><td><code>style</code></td> <td> <p>List of formatting options, see the individual methods for the style options they support.</p> </td></tr> <tr valign="top"><td><code>...</code></td> <td> <p>Additional arguments for methods.</p> </td></tr> </table> <h3>Details</h3> <h4>Default style</h4> <div class="sourceCode r"><pre>months <- month.name[1:3] cli_text("{.val {months}}") </pre></div> <div class="asciicast" style="color: #172431;font-family: 'Fira Code',Monaco,Consolas,Menlo,'Bitstream Vera Sans Mono','Powerline Symbols',monospace;line-height: 1.300000"><pre> #> <span style="color: #268BD2;">"January"</span>, <span style="color: #268BD2;">"February"</span>, and <span style="color: #268BD2;">"March"</span> </pre></div> <div class="sourceCode r"><pre>nums <- 1:5 / 7 cli_text("{.val {nums}}") </pre></div> <div class="asciicast" style="color: #172431;font-family: 'Fira Code',Monaco,Consolas,Menlo,'Bitstream Vera Sans Mono','Powerline Symbols',monospace;line-height: 1.300000"><pre> #> <span style="color: #268BD2;">0.142857142857143</span>, <span style="color: #268BD2;">0.285714285714286</span>, <span style="color: #268BD2;">0.428571428571429</span>, #> <span style="color: #268BD2;">0.571428571428571</span>, and <span style="color: #268BD2;">0.714285714285714</span> </pre></div> <h4>Styling with themes</h4> <div class="sourceCode r"><pre>nums <- 1:5 / 7 divid <- cli_div(theme = list(.val = list(digits = 3))) cli_text("{.val {nums}}") cli_end(divid) </pre></div> <div class="asciicast" style="color: #172431;font-family: 'Fira Code',Monaco,Consolas,Menlo,'Bitstream Vera Sans Mono','Powerline Symbols',monospace;line-height: 1.300000"><pre> #> <span style="color: #268BD2;">0.143</span>, <span style="color: #268BD2;">0.286</span>, <span style="color: #268BD2;">0.429</span>, <span style="color: #268BD2;">0.571</span>, and <span style="color: #268BD2;">0.714</span> </pre></div> <p>It is possible to define new S3 methods for <code>cli_format</code> and then these will be used automatically for <code style="white-space: pre;">{.val ...}</code> expressions. </p> <div class="sourceCode r"><pre>cli_format.month <- function(x, style = NULL, ...) { x <- encodeString(substr(x, 1, 3), quote = "\"") NextMethod("cli_format") } registerS3method("cli_format", "month", cli_format.month) months <- structure(month.name[1:3], class = "month") cli_text("{.val {months}}") </pre></div> <div class="asciicast" style="color: #172431;font-family: 'Fira Code',Monaco,Consolas,Menlo,'Bitstream Vera Sans Mono','Powerline Symbols',monospace;line-height: 1.300000"><pre> #> <span style="color: #268BD2;">"Jan"</span>, <span style="color: #268BD2;">"Feb"</span>, and <span style="color: #268BD2;">"Mar"</span> </pre></div> <h3>See Also</h3> <p><code><a href="cli_vec.html">cli_vec()</a></code> </p> <hr /><div style="text-align: center;">[Package <em>cli</em> version 3.4.1 <a href="00Index.html">Index</a>]</div> </body></html>