如何在R包函数中使用非ASCII符号(例如£)? [英] How to use a non-ASCII symbol (e.g. £) in an R package function?

查看:142
本文介绍了如何在R包函数中使用非ASCII符号(例如£)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的一个R包中有一个简单的函数,其中一个参数为symbol = "£":

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)) 
}

但是在运行R CMD check时,出现此警告:

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

肯定是导致问题的£符号.如果我将其替换为合法的ASCII字符(如$),则警告消失.

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

问题:如何在函数自变量中使用£而不引起R CMD check警告?

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

推荐答案

在第1.7.1节.

此页面中的建议之一是使用Unicode编码\uxxxx.由于£是Unicode 00A3,因此您可以使用:

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"

这篇关于如何在R包函数中使用非ASCII符号(例如£)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆