Using non-ASCII characters inside functions for packages

I am trying to write a function equivalent to scales::dollar that adds a pound (£) symbol to the beginning of a figure. Since the weight code is so stable, I used it as a framework and simply replaced $ with £.

Example truncated function:

 pounds<-function(x) paste0("Ā£",x) 

When I run CHECK, I get the following:

 Found the following file with non-ASCII characters: pounds.R Portable packages must use only ASCII characters in their R code, except perhaps in comments. Use \uxxxx escapes for other characters. 

Looking through the Writing R Extension Guide, he does not give much help (IMO) on how to solve this problem. He mentions \ uxxxx and says that it refers to Unicode characters.

Unicode character search gives me the £ code, but the manual I can find for \uxxxx is minimal and applies to Java on W3schools.

My question is:

How to implement the use of non-Unicode characters in R-functions using the \ uxxxx screens and how does the use affect the display of such characters after using the function?

+12
string r unicode ascii
source share
3 answers

To exit \ uxxxx you need to know the hexadecimal number of your character. You can determine this using charToRaw :

 sprintf("%X", as.integer(charToRaw("Ā£"))) [1] "A3" 

Now you can use this to indicate your non ascii character. \u00A3 and £ represent the same character.

Another option is to use stringi::stri_escape_unicode :

 library(stringi) stringi::stri_escape_unicode("āž›") # "\\u279b" 

This informs you that "\u279b" represents the character "āž›" .

+13
source share

Try the following:

 pounds<-function(x) paste0("\u00A3",x) 
+10
source share

The stringi package can be useful in the following situations:

 library(stringi) stri_escape_unicode("Ā£") #> [1] "\\u00a3" 
+2
source share

All Articles