Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
394 views
in Technique[技术] by (71.8m points)

warnings - How to use a non-ASCII symbol (e.g. £) in an R package function?

I have a simple function in one of my R packages, with one of the arguments symbol = "£":

formatPound <- function(x, digits = 2, nsmall = 2, symbol = "£"){ 
  paste(symbol, format(x, digits = digits, nsmall = nsmall)) 
}

But when running R CMD check, I get this warning:

* checking R files for non-ASCII characters ... WARNING
Found the following files with non-ASCII characters:
  formatters.R

It's definitely that symbol that causes the problem. If I replace it with a legitimate ASCII character, like $, the warning disappears.

Question: How can I use in my function argument, without incurring a R CMD check warning?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Looks like "Writing R Extensions" covers this in Section 1.7.1 "Encoding Issues".


One of the recommendations in this page is to use the Unicode encoding uxxxx. Since £ is Unicode 00A3, you can use:

formatPound <- function(x, digits=2, nsmall=2, symbol="u00A3"){
  paste(symbol, format(x, digits=digits, nsmall=nsmall))
}


formatPound(123.45)
[1] "£ 123.45"

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...