2015-02-19 10 views
8

È possibile utilizzare la funzione knitr knit2pdf() direttamente con i file R Markdown (Rmd)? Ho visto vari tutorial/note di classe che sembrano suggerire che possano, ad es. here e here (Ctrl + F "knit2pdf" in entrambi).Utilizzo di knit2pdf con file Rmd

Ma quando prendo un file RMD semplice (salvato come "test.rmd")

--- 
title: "knit2pdf test" 
author: "A Aaronson" 
date: "Thursday, February 19, 2015" 
output: pdf_document 
--- 

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>. 

When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this: 

```{r} 
summary(cars) 
``` 

You can also embed plots, for example: 

```{r, echo=FALSE} 
plot(cars) 
``` 

Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot. 

e cercare

library(knitr) 
knit2pdf("test.Rmd") 

ottengo il seguente errore

risultati in:

output file: test.md 

Error: running 'texi2dvi' on 'test.md' failed 

LaTeX errors: 
! Emergency stop 
*** (job aborted, no legal \end found) 

! ==> Fatal error occurred, no output PDF file produced! 
! ==> Fatal error occurred, no output PDF file produced! 
In addition: Warning message: 
running command '"C:\PROGRA~2\MIKTEX~1.9\miktex\bin\texi2dvi.exe" --quiet --pdf "test.md" --max-iterations=20 -I "C:/PROGRA~1/R/R-31~1.2/share/texmf/tex/latex" -I "C:/PROGRA~1/R/R-31~1.2/share/texmf/bibtex/bst"' had status 1 

Clicki Il pulsante "Knit PDF" genera sempre correttamente un pdf. Quindi mi manca un passaggio intermedio?

Vorrei aggiungere che knit2pdf() con i file RNW funziona come previsto per me, anche se io ancora ottenere l'avvertimento

running command '"C:\PROGRA~2\MIKTEX~1.9\miktex\bin\texi2dvi.exe" --quiet --pdf "rnwtest.tex" --max-iterations=20 -I "C:/PROGRA~1/R/R-31~1.2/share/texmf/tex/latex" -I "C:/PROGRA~1/R/R-31~1.2/share/texmf/bibtex/bst"' had status 1 

aiuto molto apprezzato.

+1

Controllo knit2pdf, vedo che knit2pdf() si aspetta un documento Rnw o RRST che è il motivo per cui "knit2pdf() con i file RNW funziona come previsto", ma non con Rmd. Penso che "facendo clic sul pulsante" Knit PDF "venga sempre generato correttamente un pdf" perché una versione Rnw o prima viene generata in una fase preliminare e poi knit2pdf() chiama sul risultato per produrre il pdf (o qualcosa del genere). Quindi è necessario capire come produrre la prima versione dal tuo Rmd, quindi utilizzare rst2pdf() – shekeine

risposta

7

Il file di input è nel formato .

È necessario utilizzare la funzione render() nel pacchetto per compilare il documento.

Prova:?

library("rmarkdown") 
render("temp.rmd") 

enter image description here

Problemi correlati