2

I had a r markdown file copied from Roger Peng's tutorial. And I was able to knit to html and Word but had problems knitting to pdf. The test.Rmd code:

My First Knitr Document =============================== This is some text (i.e. a text chunk). here is a code chunk ```{r} set.seed(1) x <- rnorm(100) mean(x) ``` 

After clicking 'knit to pdf', error:

Output created: test.pdf Error in tools::file_path_as_absolute(output_file) : file 'test.pdf' does not exist Calls: <Anonymous> -> <Anonymous> In addition: Warning messages: 1: running command '"pdflatex" -halt-on-error -interaction=batchmode "test.tex"' had status 1 2: In readLines(logfile) : incomplete final line found on 'test.log' Execution halted 

When I run 'latexmk -version' in cmd (windows), I got:

latexmk: warning: running with administrator privileges latexmk: The script engine could not be found latexmk: Data: scriptEngine="perl.exe" 

My session info:

R version 3.4.4 (2018-03-15) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 7 x64 (build 7601) Service Pack 1 Matrix products: default locale: [1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 [3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C [5] LC_TIME=English_United States.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] tinytex_0.4 sp_1.2-7 loaded via a namespace (and not attached): [1] Rcpp_0.12.16 lattice_0.20-35 withr_2.1.2 digest_0.6.15 rprojroot_1.3-2 grid_3.4.4 [7] R6_2.2.2 backports_1.1.2 magrittr_1.5 evaluate_0.10.1 httr_1.3.1 stringi_1.1.7 [13] rmarkdown_1.9 devtools_1.13.5 tools_3.4.4 stringr_1.3.0 yaml_2.1.18 compiler_3.4.4 [19] memoise_1.1.0 htmltools_0.3.6 knitr_1.20 

My MikTex version: basic-miktex-2.9.6.

Updated, to be more precise, the same code worked well on mac (R version 3.4.0 though).
More information: I installed RStudio on E disk while MikTex on C disk.
Also, I am able to use R Sweave compile pdf.

I appreciate if anyone could help.

1 Answer 1

3

If you click on the little arrow besides "knit" you should be able to "knit to pdf". R markdown will then add the correct YAML header to your document:

--- output: pdf_document: default --- My First Knitr Document =============================== This is some text (i.e. a text chunk). here is a code chunk ```{r} set.seed(1) x <- rnorm(100) mean(x) ``` 

This works for me. Just insert the Header and click on knit.

Next time: please take a quick look at the Documentation

Hope this helps :)

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Kaktus. I do have the header, just forgot to post. Also I can run the Rmd file successfully on mac, even without the header.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.