Converting Rmarkdown to PDF without RStudio

本小妞迷上赌 提交于 2019-12-07 14:48:02

问题


I would like to convert a *.Rmd to document to PDF without rstudio being available.

Current approach

Current approach follows the following steps:

  1. *.Rmd document is passed to knitr: knit(input = "report.Rmd"))
  2. Obtained md is converted via pandoc:

    # Convert
    pandoc --smart --to latex \
           --latex-engine pdflatex \
           -s report.md \
           -o report.PDF
    

Problems

This results in the following problems, the top section of the Rmarkdown document:

---
title:  "Report Title"
author: "Person"
output: pdf_document
classoption: landscape
---

and shows as:

all text is centered, whereas I would like for it to be left-aligned:

Possible approach

I would like to make use of the rmarkdown::render; however, despite setting RSTUDIO_PANDOC (as discussed here), the command fails on pandoc not being available.

Desired outcome

I don't care much whether the utilised mechanism makes use of the rmarkdown::render, what I want to achieve is:

  • Landscape page layout across all pages
  • Left-aligned text
  • Ability to exercise minimum control over the document by controlling default fonts

  • Ideally, I would like to do as much as in the *.Rmd file as possible without the need to add parameters to the pandoc command.

Updates, following comments

  • I'm working on Linux and pandoc is installed, I can execute pandoc command pass files and generate exports with no problems. It only doesn't work with the rmarkdown::render package.
  • Concerning the hooks and *.Rmd files, this is what I'm trying to understand as I see that that the first section of my *.Rmd file is ignored. The current process looks as follows:
    • *.Rmd (not much in it, just title section and dummy text and code that renders but wrongly justified) >
    • *.R file running one line knit(input = "report.Rmd")) >
    • *.sh file running pandoc command and generating PDF

Concerning:

if all that is in place, it is indeed just a call to rmarkdown::render(...)

The rmarkdown::render(...) fails: Error: pandoc version 1.12.3 is required and was not found ... However:

>> rmarkdown::pandoc_available()
[1] TRUE

and:

$ pandoc -v
pandoc 1.9.4.1 (...)

The RSTUDIO_PANDOC points to pandoc.


回答1:


A few things:

  • "the command fails on pandoc not being available." well you must have pandoc installed in order to call it -- but you didn't say what OS you have. On Linux it is pretty trivial to install pandoc from the package manager; otherwise jgm has binaries for you on the site; "should" be similar on OS X

  • for different styling you need to modify the LaTeX code which you can via numerous hooks to include macro files; see the RMarkdown cheat sheets for detail

  • if you want to exercise more control, you can supply your own template; I have done so in the tint package (which is also on CRAN)

  • if all that is in place, it is indeed just a call to rmarkdown::render(...)



回答2:


Error: pandoc version 1.12.3 is required and was not found

I think the error says it plainly: you need pandoc 1.12.3 and you have pandoc 1.9.4.1

I do not know, however, why such a specific version is required.



来源:https://stackoverflow.com/questions/41611694/converting-rmarkdown-to-pdf-without-rstudio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!