Convert non-ASCII to character representations beginning with backslash u (\u) in R?

こ雲淡風輕ζ 提交于 2021-01-28 19:05:55

问题


Running R CMD check --as-cran gives

Portable packages must use only ASCII characters in their R code,
except perhaps in comments.
Use \uxxxx escapes for other characters.

What are \uxxxx, and more importantly, how can I convert non ASCII characters into them?

What I know so far

  • ?iconv is very informative, and looks powerful, but I see nothing of the form \u
  • this python documentation indicates \uxxxx are

Character with 16-bit hex value xxxx (Unicode only)

Question

How can I convert non-ASCII characters into character representations of the form \uxxxx

Some examples c("¤", "£", "€", "¢", "¥", "₧", "ƒ")


回答1:


You have stri_escape_unicode from stringi to escape unicode:

stringi::stri_escape_unicode(c("¤", "£", "€", "¢", "¥", "₧", "ƒ"))
## [1] "\\u00a4" "\\u00a3" "\\u20ac" "\\u00a2" "\\u00a5" "P"       "\\u0192"

I have an addin based on that to remove non ascii characters between quotes in function here : https://github.com/dreamRs/prefixer



来源:https://stackoverflow.com/questions/60723970/convert-non-ascii-to-character-representations-beginning-with-backslash-u-u-i

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!