showNonASCII {tools}R Documentation

Pick Out Non-ASCII Characters

Description

This function prints elements of a character vector which contain non-ASCII bytes, printing such bytes as a escape like ‘⁠<fc>⁠’.

Usage

showNonASCII(x)

showNonASCIIfile(file)

Arguments

x

a character vector.

file

path to a file.

Details

This was originally written to help detect non-portable text in files in packages.

It prints all elements of x which contain non-ASCII characters, preceded by the element number and with non-ASCII bytes highlighted via iconv(sub = "byte").

However, this rendering depends on iconv(to = "ASCII") failing to convert, and macOS 14 no longer does so reliably so for example permille (‘⁠\u2030⁠’) is rendered as o/oo.

Value

The elements of x containing non-ASCII characters will be returned invisibly.

Examples

out <- c(
"fran\xE7ais: test of showNonASCII():",
"\\details{",
"   This is a good line",
"   This has an \xfcmlaut in it.",
"   OK again.",
"}")
f <- tempfile()
cat(out, file = f, sep = "\n")

showNonASCIIfile(f)
unlink(f)

[Package tools version 4.4.1 Index]