output_utf8 {utf8}R Documentation

Output Capabilities

Description

Test whether the output connection has ANSI style escape support or UTF-8 support.

Usage

output_ansi()

output_utf8()

Details

output_ansi tests whether the output connection supports ANSI style escapes. This is TRUE if the connection is a terminal and not the Windows GUI. Otherwise, it is true if running in RStudio 1.1 or later with ANSI escapes enabled, provided stdout() has not been redirected to another connection by sink().

output_utf8 tests whether the output connection supports UTF-8. For most platforms l10n_info()$`UTF-8` gives this information, but this does not give an accurate result for Windows GUIs. To work around this, we proceed as follows:

Value

A logical scalar indicating whether the output connection supports the given capability.

See Also

.Platform, isatty, l10n_info, Sys.getlocale

Examples

# test whether ANSI style escapes or UTF-8 output are supported
cat("ANSI:", output_ansi(), "\n")
cat("UTF8:", output_utf8(), "\n")

# switch to C locale
Sys.setlocale("LC_CTYPE", "C")
cat("ANSI:", output_ansi(), "\n")
cat("UTF8:", output_utf8(), "\n")

# switch to native locale
Sys.setlocale("LC_CTYPE", "")

tmp <- tempfile()
sink(tmp) # redirect output to a file
cat("ANSI:", output_ansi(), "\n")
cat("UTF8:", output_utf8(), "\n")
sink() # restore stdout

# inspect the output
readLines(tmp)

[Package utf8 version 1.1.2 Index]