简体   繁体   中英

R markdowns error while using render to pdf: ! Package inputenc Error: Unicode char \u8:

I am having problems when I run the following code:

for (i in as.vector(unidades$Unid_Fed)){
    rmarkdown::render(input = "file.path/MR.Rmd",
                      output_format = "pdf_document",
                      output_file = paste("Texto_",i, Sys.Date(), ".pdf", sep='_'),
                      output_dir = "file.path/Multi_reports")}
---

and the MR.Rmd is:

---
title: "multiple pdf reports with special character ç í ã"
author: ''
date: ''
header-includes: 
\usepackage{graphicx}
\usepackage{fancyhdr}
\usepackage[utf8]{inputenc}
\pagestyle{fancy}
\setlength\headheight{28pt}
\fancyhead[L]{\includegraphics[width=2.2cm]{ibge.png}}
\fancyfoot[LE,RO]{}
\usepackage{titling}
\pretitle{\begin{center}
\includegraphics[width=6cm]{ibge.png}\\[\bigskipamount]}
\posttitle{\end{center}}
\usepackage[utf8]{inputenc}

output: pdf_document
---
##  Text - First part 
\begingroup\Huge
\begin{center}
Other text using special characters like Ç í ã... 
\end{center}
\endgroup

When I run this, I have output problems like this: ! Package inputenc Error: Unicode char \\u8:Â not set up for use with LaTeX.

Error: Failed to compile D:/Users/...

I discovered: I just need to use encoding="UTF-8" in render:

for (i in as.vector(unidades$Unid_Fed)){
rmarkdown::render(input = "file.path/MR.Rmd",
                  output_format = "pdf_document",
                  output_file = paste("Texto_",i, Sys.Date(), ".pdf", sep='_'),
                  output_dir = "file.path/Multi_reports",
                  encoding="UTF-8")}
---

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM