Domanda

I have hard time to get my table printed with diacritics via knitr package and pandoc. I believe the Name.md file is produced correctly, but gives me error at the pandoc level. What I'm doing wrong? Without diacritics it works perfectly.

Here is example and steps I follow:

Replicate table in R

SampleTable <- data.frame(Nazov=c("Kratkodobé záväzky (TA)","Dlhodobé záväzky 
                                 (LA)","Záväzky celkovo (TA)"))

I run *.Rmd file to create Name.md file

```{r, echo=FALSE, dpi=600, fig.width=12, fig.height=15, fig.cap="Finančná štruktúra"}
   print(xtable(SampleTable))
```

Convert .md into .pdf

knit("Name.rmd")


system(paste("pandoc -V geometry:margin=1in -o", "Report", ".pdf ", "Name", ".md", 
              sep=""))

EDIT: The error:

pandoc.exe: Cannot decode byte '\x20': Data.Text.Encoding.decodeUtf8: Invalid UTF-8
            stream

Warning message:
running command 'pandoc -V geometry:margin=1in -oReport7.pdf ReportNew.md' had status 1
È stato utile?

Soluzione

After viewing your file in a text editor like "geany" which lets you see the file encoding easily (File > Properties), you'll see that the file encoding is ISO-8859-1.

However, as mentioned on the Pandoc man page:

Pandoc uses the UTF-8 character encoding for both input and output. If your local character encoding is not UTF-8, you should pipe input and output through iconv:

iconv -t utf-8 input.txt | pandoc | iconv -f utf-8

As such, what I did at my terminal was (assuming you've changed to the directory your .md file is stored in):

iconv -f ISO-8859-1 -t UTF-8 md_file.md > new.md
pandoc new.md -o test.pdf

If you wish to do this from R, paste together the commands as you have done in your existing question.

Here's the output I got:

enter image description here

Note: I should mention that I am on Ubuntu and iconv is fairly standard in Unix systems.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top