In RStudio, when i go for convert my Markdown file to PDF then it gives me the error:
output file: report.knit.md
! Package inputenc Error
I know I am a bit late for this, but I just had almost the same error (minus the pandoc part).
The problem was that I copy pasted a sentence from wikipedia, which had a dash character which was not utf8 formatted. I replaced the dash and it worked.
Latex fails (with an encoding error) to create a pdf if there are "special" characters in your document, like incorrect whitespace/newline characters, or characters with accents. An easy way to check copy-pasted text is to first paste it into a very basic text editor, like nedit.
I had the same problem, but with a very long document. Rather than manually split the document to find the offending non-utf8 text, I found this solution (for users of RStudio), saving the document in the utf8 format, worked a treat and saved lots of time:
Here are the original links:
Here is a less technical solution but it worked for me when everything else didn't. Try deleting (after copying your code elsewhere) parts of your file and then kniting it. Then by process of elimination you will be able to narrow it down to the character/s that are causing the problem. Keep in mind there may be multiple occurrences of the problem. To make it easier to find the character the error message gave me the utf code of the character and I was able to look up what it was. Apparently there was a special 'fi' character used five times in the text I copied and pasted from so I looked for and replaced them with a normal 'fi'.
Given the almost identical error message, I tried following @scoa's suggestion, but putting that line in the YAML header did not change the error, so for whatever reason, Knitr wasn't looking there to determine the LaTex engine. However, next to the "Knit PDF" button in the control bar is a settings menu that allows you to specify the LaTex ending in the "Advanced" pane. This solved the problem for me. It produces a slight variation on the suggestion above, modifying the YAML header thus:
output:
pdf_document:
latex_engine: xelatex
I can see that @scoa may have assumed the YAML output was already formatted this way, but what I was missing was the colon after 'pdf_document'. Using the settings dialogue created the proper syntax in the header.
RStudio version 0.99.896, knitr version 1.12.3.
I do have the same problem recently.
I solve this problem in a straightforward way, maybe stupid you think. Obviously, the error suggests that some characters or signs in your code could not recognize properly by LaTeX.
So, I remove the code from the R markdown part by part to find which part caused this problem. Finally, I found the part that resulted in the error in my code. Just a very short description in my code.
### Platform:Affymetrix A-AFFY-2-Affymetrix GeneChip Arabidopsis Genome [ATH1-121501].
I remember I copy this information from webpage or other somewhere.
So I type this part to my code by myself. It can run and generate the pdf file without any error. Now, what is the difference between the copy version and the version of my typing?
To be clear, I show you in the below attached figure:
.
This is just one example I think. I want to point out that it is always problematic when you copy something from an unknown resource file into your code.
Hope this can help you and other people who were frustrated by this problem.