EVOLUTION-MANAGER
Edit File: has_color.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: Does the current R session support ANSI colors?</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 has_color {crayon}"><tr><td>has_color {crayon}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Does the current R session support ANSI colors?</h2> <h3>Description</h3> <p>Does the current R session support ANSI colors? </p> <h3>Usage</h3> <pre> has_color() </pre> <h3>Details</h3> <p>The following algorithm is used to detect ANSI support: </p> <ul> <li><p> If the <code>crayon.enabled</code> option is set to <code>TRUE</code> with <code><a href="../../base/html/options.html">options()</a></code>, then <code>TRUE</code> is returned. If it is set to something else than <code>TRUE</code> (typically <code>FALSE</code>), then <code>FALSE</code> is returned. </p> </li> <li><p> Otherwise, if the standard output is not a terminal, then <code>FALSE</code> is returned. </p> </li> <li><p> Otherwise, if the platform is Windows, <code>TRUE</code> is returned if running in ConEmu (<a href="https://conemu.github.io/">https://conemu.github.io/</a>) or cmder (<a href="http://cmder.net">http://cmder.net</a>) with ANSI color support. Otherwise <code>FALSE</code> is returned. </p> </li> <li><p> Otherwise, if the <code>COLORTERM</code> environment variable is set, <code>TRUE</code> is returned. </p> </li> <li><p> Otherwise, if the <code>TERM</code> environment variable starts with <code>screen</code>, <code>xterm</code> or <code>vt100</code>, or matches <code>color</code>, <code>ansi</code>, <code>cygwin</code> or <code>linux</code> (with case insentive matching), then <code>TRUE</code> is returned. </p> </li> <li><p> Otherwise <code>FALSE</code> is returned. </p> </li></ul> <h3>Value</h3> <p><code>TRUE</code> if the current R session supports color. </p> <h3>Sinks</h3> <p>Note that <code>has_color()</code> returns <code>FALSE</code> if a sink is active (see <code><a href="../../base/html/sink.html">sink()</a></code>). It assumes that the constructed string will be printed to the standard output, and <code>sink()</code> redirects to a file, and usually you don't want ANSI colors in the file. </p> <p>The same applies to the case when R's standard output is redirected to a file, from the command line, e.g.:</p> <pre>R -q -e 'cat(crayon::red("no color here\n"))' > /tmp/crayon-test.txt cat /tmp/crayon-test.txt </pre> <h3>Examples</h3> <pre> has_color() </pre> <hr /><div style="text-align: center;">[Package <em>crayon</em> version 1.3.4 <a href="00Index.html">Index</a>]</div> </body></html>