How to convert R Markdown to PDF?

后端 未结 8 1199
天命终不由人
天命终不由人 2020-11-28 00:36

I\'ve previously asked about the commands for converting R Markdown to HTML.

What is a good way to convert R Markdown files to PDF documents?

8条回答
  •  一向
    一向 (楼主)
    2020-11-28 01:23

    For an option that looks more like what you get when you print from a browser, wkhtmltopdf provides one option.

    On Ubuntu

    sudo apt-get install wkhtmltopdf
    

    And then the same command as for the pandoc example to get to the HTML:

    RMDFILE=example-r-markdown  
    Rscript -e "require(knitr); require(markdown); knit('$RMDFILE.rmd', '$RMDFILE.md'); markdownToHTML('$RMDFILE.md', '$RMDFILE.html', options=c('use_xhml'))"
    

    and then

    wkhtmltopdf example-r-markdown.html example-r-markdown.pdf
    

    The resulting file looked like this. It did not seem to handle the MathJax (this issue is discussed here), and the page breaks are ugly. However, in some cases, such a style might be preferred over a more LaTeX style presentation.

提交回复
热议问题