问题
I would like to convert a *.Rmd
to document to PDF without rstudio being available.
Current approach
Current approach follows the following steps:
*.Rmd
document is passed toknitr
:knit(input = "report.Rmd"))
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 thepandoc
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 thermarkdown::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 lineknit(input = "report.Rmd"))
>*.sh
file runningpandoc
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 installpandoc
from the package manager; otherwise jgm has binaries for you on the site; "should" be similar on OS Xfor 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