PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, July 17, 2022

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

 July 17, 2022     ascii, package, r, warnings     No comments   

Issue

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?


Solution

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"


Answered By - Dirk Eddelbuettel
Answer Checked By - Willingham (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing