Using non-ASCII characters inside functions for packages
Try this:
pounds<-function(x) paste0("\u00A3",x)
The stringi package can be useful is these situations:
library(stringi)
stri_escape_unicode("£")
#> [1] "\\u00a3"
For the \uxxxx escapes, you need to know the hexadecimal number of your character. You can determine it using charToRaw
:
sprintf("%X", as.integer(charToRaw("£")))
[1] "A3"
Now you can use this to specify your non-ascii character. Both \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 "➛"
.