我的一个 R 包中有一个简单的函数,其参数之一 symbol = "£"
:
formatPound <- function(x, digits = 2, nsmall = 2, symbol = "£"){
paste(symbol, format(x, digits = digits, nsmall = nsmall))
}
但是当运行R CMD check
时,我收到此警告:
* checking R files for non-ASCII characters ... WARNING
Found the following files with non-ASCII characters:
formatters.R
这绝对是 £
符号导致了问题。如果我将其替换为合法的 ASCII 字符,例如 $
,警告就会消失。
问题:如何在函数参数中使用 £
,而不引发 R CMD check
警告?
最佳答案
看起来“编写 R 扩展”在第 1.7.1 节 "Encoding Issues" 中介绍了这一点.
<小时/>本页的建议之一是使用 Unicode 编码 \uxxxx
。由于 £ 是 Unicode 00A3,因此您可以使用:
formatPound <- function(x, digits=2, nsmall=2, symbol="\u00A3"){
paste(symbol, format(x, digits=digits, nsmall=nsmall))
}
formatPound(123.45)
[1] "£ 123.45"
关于r - 如何在 R 包函数中使用非 ASCII 符号(例如 £)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11452796/