-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Foreign characters in R figures don't work #17
Comments
Try adding the
With this, I am able to successfully Trying a simple
|
I guess I should mention that I'm on a Mac; I'm not really sure if this is relevant for folk on Windows. |
Ooh, this looks promising. I've been toying around with it for the past hour, trying to get rid of the conversion failure warnings, but to no avail. It's a common problem for R graphics and knitr apparently (see the Encoding of multibyte characters section at the knitr manual). It looks like you can take care of the problem by manually specifying an encoding, but there's no UTF-8 encoding (apparently), so I don't know how to best generalize it. I'd love to know how RStudio does it. |
Try adding
How does that work? It seems to have gotten rid of the conversion warnings for me. Cf. this question on Stack Overflow. |
Using |
Fantastic - that works! The only downside to this is that the user has to select an encoding that fits all the characters they're using in their document. If they use Chinese, Arabic, or Cyrillic characters, they'll need to change it accordingly. |
However, I just tested it in RStudio and it has the same problem (and same solution; setting |
So, for future reference, adding a separate block with
|
Maybe this should be a separate issue, or maybe even this enters more into the jurisdiction of @LaTeXing, but it is directly related to the foregoing discussion, so I'll just add it here for the moment. The solution above for Rmd documents does not seem to work for Rtex/Rnw/etc., where "č" and other non-English characters are rendered as ".." or as Unicode; admittedly, I have yet to manage to successfully incorporate the Input:
Output: |
Yes, this. |
I've been working with another person (not on GitHub) with this exact issue ( However, I don't know if this is a knitr issue. When he runs knitr from the Terminal, everything works great and all characters show up as expected. Building the |
I think you may be right about the issue being due to ST rather than to knitr, although I don't know much at all. In my encoding-related question on SO, @randy3k in a comment suggests I run:
in ST's console and comparing the results with those gleaned from running, in the terminal:
It seems that, for me at least, there is some sort of disconnect (but, again, I don't know much on the subject): ST yields Adding |
My terminal gives me But after creating Try doing that and see if the |
Adding Input:
Output: 1 Running the bit of Python in ST gives me |
Oh, we're so close :) The missing characters in the actual body of the PDF is probably due to LaTeX. Add this to the preamble: |
That did it! Thanks very much.
|
Summary
|
Thanks so much for your help! |
very interesting discussion. |
Another possible way to suppress the warnings is to use another graphic device, e.g.,
|
Yes, though I had someone else complain that the Cairo output wasn't as clear or nice looking as whatever R's default is. |
@mmarascio |
@randy3k: I'm not sure I understand; both alternatives do seem to work for me (see this relevant comment). Only, in addition, for non-ASCII characters in R plots, I need the preliminary chunk that sets |
I see. Thx for the clarification. |
Knitr is apparently really picky about the encoding of the files it builds. If you try to build a file with Unicode characters in a plot using this plugin, R will choke on the characters and return them either as
..
or their Unicode code.Here's a minimal working example (
.Rmd
):Running this with this plugin in ST3 will result in the following error:
According to this, knitr can have the file encoding passed through the
knit()
command, but it has to match the encoding of either the file itself or the system default. Hardcodingknit(…, encoding='UTF8')
into this plugin's build system isn't recommended, since Windows doesn't play well with UTF8 (apparently) and since it's supposed to match the encoding of the file. Or something.RStudio gets it right, but that's in part because they've hired Yihui :)
Any ideas on how to run the correct
knit()
command from ST?The text was updated successfully, but these errors were encountered: