Have a look at the attached picture, which comes from an RStudio notebook...
After I render this into an HTML file, I get the following:
Why do the "?" characters become "chinese?" characters?
Is there a way to fix this?
Thanks
Related
Is there a set of best practices or documentation for working with Unicode in knitr and Rmarkdown? I can't seem to get any glyphs to show up properly when knitting a document.
For example, this works in the console (in Rstudio):
> cat("\U2660 \U2665 \U2666 \U2663")
♠ ♥ ♦ ♣
But when knitting I get this:
HTML
Word
It looks like an encoding issue specific to Windows, and may be related to this issue: https://github.com/hadley/evaluate/issues/59 Unfortunately we have to wait for a fix in base R, but if you don't have to use cat(), and this expression is a top-level expression in your code chunk (e.g. not inside a for-loop or if-statement), I guess this may work:
knitr::asis_output("\U2660 \U2665 \U2666 \U2663")
It passes the character string directly to knitr and bypasses cat(), since knitr cannot reliably catch multibyte characters written out by cat() on Windows -- it depends on whether the characters can be represented by your system's native encoding.
For anyone else who came across this after trying to get emoji support in Rstudio/Rmarkdown documents, another possible issue is that if the file encoding isn't set to UTF-8, the resulting compiled document won't support emojis either.
In order for emoji to work in Rmarkdown, you must change the file encoding of the Rmd document. Go to File -> Reopen with encoding, then select UTF-8.
Once you have ensured the file is open in UTF-8 encoding, you should be able to compile with emoji support.
You should even be able to paste emoji from a browser directly into the document. 😺
It is probably a good idea to change the default encoding for all files to UTF-8 so that you don't have to deal with this issue again.
Unicode: Inline
Phew, that was close `r knitr::asis_output("\U1F605 \U2660 \U2665 \U2666 \U2663")`
Unicode: Block
```{r, echo=FALSE}
knitr::asis_output("Phew, that was close \U1F605 \U2660 \U2665 \U2666 \U2663")
```
The emo package
Unfortunately, this package isn't yet on CRAN, but it can be installed with devtools::install_github("hadley/emo")
emo::ji("face")
There are some more examples here
I am trying to read a file containing non-ASCII characters in R, please see the screenshot below.
enter image description here
When I use readLines() to read the file, I get simply few lines of content.
enter image description here
Please help! Any answer is highly appreciated.
I am trying to view characters of multiple of languages in RStudio. What I find unusual is I am able to view these in the console, but not in the viewer. UTF-8 encoded characters appear like 'U+3042', 'U+500B', etc. in the viewer.
Is there a way to get the viewer to display the actual characters instead of the encoded character?
Here are a couple of images showing what I mean -
In console: https://ibb.co/T0681H7
In viewer: https://ibb.co/QnxF25c
This is a known issue in RStudio. Feel free to comment/upvote here:
https://github.com/rstudio/rstudio/issues/4193
I have a japanese text csv file seperated by tab
It was written in utf-8 using python csv package
However,when i import it with command in RStudio as below
A <- read.csv("reviews4.csv",sep="\t",header = F,encoding="UTF-8")
The japanese character would show like this:
<U+8AAC>明無<U+3057><U+306B><U+5185>容量<U.....
I think it only shows kanji parts correctly.
I've tried encoding = "CP932"
It would show:
隤祆<98><81><86>捆<87><....
Then I tried another way: click the file in the lower right and select "import dataset"
Then strange things happend:
When I choose "First rows as names",the colnames show japanese properly
but when I disable that,it show uncorrectly.
Can anyone help me importing japanese csv properly?
Thank you so much!
Use fileEncoding="UTF-8" instead of encoding="UTF-8".
all. I am a beginner of R.
I try to read a text file (csv) into R. The correct version should be "Our mission, which has...", however, after I loaded the file, I got "Our U+00A0 mission, which has..."
Here is how I load my code:
mission = read.csv(file.choose(),header=T, stringsAsFactors=F, encoding="UTF-8")
I know is unicode for space, but can anyone let me know how can my Rstudio show a space instead of
Can anyone please help?