R: Use Japanese instead of Japanese in scripts

In R, if there is Japanese in the script, it sometimes causes inconvenience, so we deal with it in the following way.

# R
intToUtf8(c(12371, 12435, 12395, 12385, 12399))
## [1] "Hello"

Which number the character you want corresponds to

# R
utf8ToInt("Hello")
[1] 12371 12435 12395 12385 12399

I checked it once and tried to write it in the script without using Japanese.

You can also look it up in Python.

# python3
[ord(s) for s in "Hello"]
## [12371, 12435, 12395, 12385, 12399]

For python2 series, u "" is required.

# python2
[ord(s) for s in u"Hello"]
## [12371, 12435, 12395, 12385, 12399]

Postscript (thanks: @shiracamus)

It seems that you can also specify Unicode in R.

"\u3053\u3093\u306b\u3061\u306f"
## [1] "Hello"

Is the code specified in hexadecimal? There are many ways to get the hexadecimal code.

In R, it looks like this.

# R
sprintf("%x", utf8ToInt("Hello"))
[1] "3053" "3093" "306b" "3061" "306f"

You can use hex in Python.

# python3
[hex(ord(s)) for s in "Hello"]
['0x3053', '0x3093', '0x306b', '0x3061', '0x306f']

Postscript

By the way, when embedding in R package, if you use a character string of "\ u ..." format in the function definition, the following warning seems to appear.

plotat.Rd: non-ASCII input and no declared encoding

It seems that it is not recommended to use double-byte characters in R help.

Recommended Posts

R: Use Japanese instead of Japanese in scripts
Let's use usercustomize.py instead of sitecustomize.py
Let's use tomotopy instead of gensim
Use of constraints file added in pip 7.1
Hello world instead of localhost in Django
Put Linux in your Chromebook and use R ...
Use the Java SDK of GoogleMapsAPI to get the result of reverse GeoCoding in Japanese.
Summary of how to use MNIST in Python
Uncertainty of Japanese unide code in Tacotron 2 series
Make a joyplot-like plot of R in python
Date of Address already in use error in Flask
[Implementation explanation] How to use the Japanese version of BERT in Google Colaboratory (PyTorch)
Use urlparse.urljoin instead of os.path.join for Python URL joins
Let's use the open data of "Mamebus" in Python
Use date to x-axis of tsplot depicted in seaborn
How to use Spacy Japanese model in Google Colaboratory
I want to use the R dataset in python
EP 7 Use List Comprehensions Instead of map and filter
Convenient use of ipython
Use config.ini in Python
Use dates in Python
Use Mean in DataFrame
Use Valgrind in Python
R in Anaconda (in Ubuntu 14.04)
Japanese output in Python
Use profiler in Python
Japanese localization of Pycharm
English PDF in Japanese
Survey on the use of machine learning in real services
About the garbled Japanese part of pandas-profiling in Jupyter notebook
Enabled to input Japanese in Linux environment (crostini) of Chromebook
Sort the string array in order of length & Japanese syllabary
Make the function of drawing Japanese fonts in OpenCV general
Comparison of data frame handling in Python (pandas), R, Pig