Forums | OpenR

OpenR: R & Statistics /
Some solutions if you cannot knit to pdf


Min Yi Kau's profile picture
Posts: 5

08 April 2022, 11:04 PM

Dear all,

 

Hi, so I've encountered a few issues that caused failed to knit the pdf file. Here I provide some solutions to help, hope these could solve your problems :)

 

I think there are mainly three types of issues:

 

1. tinytex is not installed:

As previously answered by the teacher, you could use this code below to check if tinytex is installed or not:

tinytex::is_tinytex()

TRUE means you successfully installed the tinytex while FALSE means the tinytex is not installed.

To install tinytex you could use the following code; however, tinytex seems to have some issue when everyone tries to download it. 

tinytex::install_tinytex()

 

2. There is a Chinese character in the rmd file:

 

This would return with warning messages such as:

Unicode character 娉?(U+6CF0) not set up for use with LaTeX.

In this case, delete the Chinese character (usually ",") and the issue should be fixed.

 

3. Wrong encoding:

 

This one is similar to the last one, but the character could not be found. 

It is due to your computer's default code system is not Unicode.

Could check with COD (命令提示符) in the computer (in the start menu > windows system) with:

chcp

it will return with the code you use, usually the returns with 936, the windows default.

In this case, you could use File > reopen with encoding... (remember first save the file, just in case) > choose the code of your computer (if not found in the list you could check "show all the codes")

Then you might find some error code, correct them, and the issue should be fixed.

 

If the issue is still not fixed, change the "output" to the code below should fix:

 

output:

    pdf_document:

          latex_engine: xelatex

 

 

Hope this helps :)

 

 

 

 

Peng Zhao's profile picture
Posts: 128

09 April 2022, 8:21 AM

Thanks for sharing these very nice tips. Let me explain more as follows.

1. tinytex. The engineer for knitting Rmd to pdf is LaTeX. There are multiple ways for installing LaTeX. The tinytex package is the easiest and best way for R users to install LaTeX. Other ways, such as CTeX, MikTeX, and TeXLive, are also fine.  Anyway, you have to install one LaTeX, and only one LaTeX. Do not install more than one, such as tinytex + CTeX, which might have a conflict with each other. Remove one before install another.

2. Chinese characters in file/path names. There are many ways to support them, but the simplest way is not to use them. Use the 26 Latin letters with simple signs such as ",._+-()", which should be sufficient for naming a file. This has been mentioned since the very beginning of ENV221. 

3. Encoding. Does anyone have this issue? Nobody in our class has ever asked me about it. The best solution is using UTF-8. Always. It is universal and cross-platform. Change the encoding at RStudio - Tools - Options - Code - Saving - Default text encoding - Change - UTF-8. Then every time you create a new file in RStudio, it is always UTF-8.

2 results