I am trying to figure out what command and default options RStudio uses when pressing the "knit HTML" button in RStudio version 0.98.1091 because I get a slightly different intermediate markdown file when I run the knit() function from the console.
Specifically, when I use the following header for the R markdown file:
---
title: "Report Title"
author: Daddy the Runner
date: "`r format(Sys.time(), '%A, %B %d, %Y')`"
output:
html_document:
keep_md: true
---
I get the following markdown file when pressing the "Knit HTML" button:
# Report Title
Daddy the Runner
`r format(Sys.time(), '%A, %B %d, %Y')`
When I execute the following command: knit("myReport.Rmd"), I get the following markdown file:
---
title: "Report Title"
author: Daddy the Runner
date: "Saturday, January 10, 2015"
output:
html_document:
keep_md: true
---
Clearly the RStudio button is generating the intermediate markdown file using some other options but I can't find any information about it in the RStudio docs.
The key issue is the date line. For some reason, RStudio doesn't execute the inline r chunk in the header when making the markdown file. (However, it does get executed before generating the final HTML.) Whereas, the knit() function call does execute the inline chunk while generating the markdown file.
The only other difference I noticed in the two markdown files is related to the generation of plots. The two methods generate different sized graphics (command line: 504 x 504) versus (button: 672 x 480) and place them in different directories.
I tried the recommendation in this What commands are run when pressing "Knit HTML" on an R Markdown file in Rstudio 0.96? question to insert a Sys.sleep(30) call but that did not provide any information about what call RStudio used to knit the document. It did pause the output in the R Markdown console window which was unnecessary because RStudio keeps all of the output anyway. What I didn't see in the output was the command RStudio issued.
Any insight to the nature of these differences would be greatly appreciated. While I like using IDE environments and the conveniences they provide, I really like to understand what it is they are doing so I can better anticipate their behavior.
As #rawr pointed out in the comments:
rmarkdown::render('your_document.Rmd', 'html_document', 'new_titel.html')
works and creates the same document as the Knit HTML button.
When I look at the RMarkdown tab (right of Console tab) it looks like they run knitr::knit and then a fairly involved pandoc shell line
/usr/local/lib/rstudio/bin/pandoc/pandoc filename.utf8.md --to html --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash-implicit_figures --output filename.html --smart --email-obfuscation none --self-contained --standalone --section-divs --table-of-contents --toc-depth 3 --template /home/me/R/i686-pc-linux-gnu-library/3.1/rmarkdown/rmd/h/default.html --variable 'theme:flatly' --include-in-header /tmp/user/1001/RtmpKz5GnI/rmarkdown-str3bba3848bd7b.html --mathjax --variable 'mathjax-url:https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML' --no-highlight --variable highlightjs=/home/cd/R/i686-pc-linux-gnu-library/3.1/rmarkdown/rmd/h/highlight
From the very first /usr/local/lib/rstudio/bin/pandoc/pandoc I infer that they bring their own pandoc, probably figuring duplication is better than debugging to play nice with everyone's idiosyncratic pandoc versions.
So to me it looks like RStudio is doing the following:
knit
pandoc with their special pandoc version and a lot of flags
and step #2 is where the interpretation of your header
---
title: "Report Title"
author: Daddy the Runner
date: "`r format(Sys.time(), '%A, %B %d, %Y')`"
output:
html_document:
keep_md: true
---
happens.
HTH.
I believe it currently uses the html_document function in the RMarkdown package
Related
I cannot compile to a pdf-beamer from a very simple minimal example (below), with no packages.
I click - Knit - Knit to pdf
(Note this is not a duplicate of previous posts, because those all involved using Kable; I am not using it; fresh restart not calling any packages here)
I tried with and without classoption: table
Knit to html works just fine.
Restarted Rstudio; no improvement
---
title: "Untitled"
author: "Test"
date: "20 novembre 2018"
classoption: table
output:
beamer_presentation:
keep_tex: yes
---
# Test nothing
blah
```
Throws error: ! LaTeX Error: Option clash for package xcolor.
I want it to compile a beamer pdf slide show, of course.
I've put the log file here
My default.beamer (stored at /Users/yosemite/.pandoc/templates/default.beamer I think) is linked HERE
I am trying to create different sets of report based on a template.
is it possible to run this report from a command line rather than running it via RStudio (knit PDF)?
I have a vector called app where I run this report for each app and output the value. Is it possible to supply app via the command line option when running this report from the command line? Rather than having app in the Rmarkdown, I need to know if I can supply this as an argument?
Every time I run this, pdf file name is the same. How can I change this so that pdf file names is the same as the app value?
title: "Application Report"
date: "July 13th, 2017"
header-includes:
- \usepackage{longtable}
- \usepackage[table]{xcolor}
- \usepackage{colortbl}
- \usepackage[utf8]{inputenc}
output:
pdf_document:
fig_caption: yes
fig_height: 6
fig_width: 7
highlight: zenburn
number_sections: yes
toc: yes
toc_depth: 3
keep_tex: yes
tables: yes
fontsize: 15
---
```{r message=FALSE, results = 'asis', echo=FALSE, warning=FALSE, fig.width=12, fig.height=10}
app<-c("Web","DB)
for (i in app){
cat(paste("# ",app, " - Application","\n"))
}
Short Answers:
Yes
Yes
Yes
Example: I will use two files and a command line example. Using a makefile or extending the knit-application-report.R script will simplify your workflow.
First file: application-report.Rmd I've simplified from your example file for this posting. The important thing to knot is that the variable app has been defined. This variable will be used in the report title and can be used elsewhere in the report.
---
title: "`r app` Report"
date: "`r date()`"
output: pdf_document
---
This is the report for the `r app` application.
```{r}
# do stuff
```
File 2: knit-application-report.R The call to commandArgs, with trailingOnly = TRUE pass command line arguments into the R script. The name of the application is passed in as the first and only argument. That value is stored in the app variable which will then be used in the call to rmarkdown::render and used when evaluating the .Rmd file.
# file: knit-application-report.R
#
# Commandline Arguments:
# 1. appliction a character string for the app
app <- commandArgs(trailingOnly = TRUE)
rmarkdown::render(input = "application-report.Rmd",
output_file = paste0(app, ".pdf"))
The command line looks like this (from my linux command line).
me#mycomputer:~$ Rscript knit-application-report.R MyApplication
processing file: application-report.Rmd
|................................ | 50%
inline R code fragments
|.................................................................| 100%
label: unnamed-chunk-1
output file: application-report.knit.md
/usr/bin/pandoc +RTS -K512m -RTS application-report.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output MyApplication.pdf --template /home/pdewitt/R-dev/R-3.4.1/library/rmarkdown/rmd/latex/default-1.17.0.2.tex --highlight-style tango --latex-engine pdflatex --variable graphics=yes --variable 'geometry:margin=1in'
Output created: MyApplication.pdf
Note that the output is the named report MyApplication.pdf which looks like this:
I'm trying to get a watermark image like here:
How to add a watermark image on rmarkdown?
I almost did it, but as I wrote on my original question the background.png image that the \includegraphics get comes from C:\Program Files (x86)\MiKTeX 2.9\tex\plain\present
I'm currently using my Latex code from an external file using the follwing at beginning of my .Rmd:
output:
pdf_document:
includes:
in_header: header.tex
And in header.tex I'm using the following code:
\usepackage{eso-pic,graphicx,transparent}
\AddToShipoutPictureFG{
\put(0,0){%
\parbox[b][\paperheight]{\paperwidth}{%
\centering
{\transparent{0.3} \includegraphics[width=\paperwidth,height=\paperheight,%
keepaspectratio]{background.png}}%
}
}
}
But I just can't get the background.png from where my .tex file is (that is the same that my .Rmd file is).
How I tell to my .tex file get this image from the relative path to my .tex?
--EDIT--
I'm using the render function from rmarkdown to make the report, follow is a screenshot from the insides of my folder with .Rmd, the .tex file and the error when I try to insert a test.png:
"It works for me." Here is a minimal Rmarkdown file, trimmed down from one of the templates offered by RStudio:
---
title: "Demo"
author: "Dirk"
date: "October 3, 2016"
output: pdf_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## R Markdown
This is an R Markdown document. We include one figure
\includegraphics{Rlogo.png}
La fin.
I can hit the knit button just fine, or run this by hand:
/tmp$ cat includeDemo.Rmd
---
title: "Demo"
author: "Dirk"
date: "October 3, 2016"
output: pdf_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## R Markdown
This is an R Markdown document. We include one figure
\includegraphics{Rlogo.png}
La fin.
/tmp$ Rscript -e 'rmarkdown::render("includeDemo.Rmd")'
processing file: includeDemo.Rmd
|...................... | 33%
ordinary text without R code
|........................................... | 67%
label: setup (with options)
List of 1
$ include: logi FALSE
|.................................................................| 100%
ordinary text without R code
output file: includeDemo.knit.md
/usr/bin/pandoc +RTS -K512m -RTS includeDemo.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output includeDemo.pdf --template /usr/local/lib/R/site-library/rmarkdown/rmd/latex/default-1.15.2.tex --highlight-style tango --latex-engine pdflatex --variable graphics=yes --variable 'geometry:margin=1in'
Output created: includeDemo.pdf
/tmp$
Maybe something is playing tricks with you by switching from the current directory to a temporary processing directory. In which an (icky!!) absolute path may help...
I just did it.
The problem were on MiKTeX for Windows.
I just followed the steps on this answer, remembering to assure that the folder is TDS-compliant (with a tex folder in it), and after I just put the image on the tex folder.
[My environment: Win 7 Pro / R 3.2.1 / knitr_1.12.3 / R Studio Version 0.99.892]
I am trying to write an article in .Rmd format using R Studio, Knit -> PDF, and I've been following http://rmarkdown.rstudio.com/authoring_bibliographies_and_citations.html for details of how to get pandoc and pandoc-citeproc to produce a References section and citations
in the text.
My BibTeX references are in several different .bib files, which, when using
LaTeX in .Rnw files, are all found in my local texmf tree via
\bibliography{statistics, graphics}
I can't seem to make this work with pandoc-citeproc. My YAML header
has the following, that works for one .bib file, as long as it is
in the same directory as the source .Rmd file:
---
title: "Notes on Testing Equality of Covariance Matrices"
author: "Michael Friendly"
date: '`r format(Sys.time(), "%B %d, %Y")`'
output:
pdf_document:
fig_caption: yes
keep_tex: yes
number_sections: yes
csl: apa.csl
bibliography: statistics.bib
---
Following advice in the link given above, I tried:
bibliography: [statistics.bib,graphics.bib]
this gives:
pandoc-citeproc.exe: "stdin" (line 50, column 12):
unexpected ":"
expecting letter, digit, white space or "="
pandoc.exe: Error running filter pandoc-citeproc
Filter returned error status 1
[Edit: For completeness, I show the generated pandoc command, where it looks like both .bib files are passed correctly]:
"C:/Program Files/RStudio/bin/pandoc/pandoc" +RTS -K512m -RTS EqCov.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output EqCov.pdf --template "C:\R\R-3.2.1\library\rmarkdown\rmd\latex\default-1.15.2.tex" --number-sections --highlight-style tango --latex-engine pdflatex --variable graphics=yes --variable "geometry:margin=1in" --bibliography statistics.bib --bibliography graphics.bib --filter pandoc-citeproc
output file: EqCov.knit.md
So do all the following forms:
bibliography: ["statistics.bib","graphics.bib"]
bibliography:
- "statistics.bib"
- "graphics.bib"
bibliography:
- statistics.bib
- graphics.bib
Ideally, I'd like to be able to use one of the following forms, and not have to copy the .bib files to the document directory.
bibliography: ["C:/Dropbox/localtexmf/bibtex/bib/statistics.bib","C:/Dropbox/localtexmf/bibtex/bib/graphics.bib"]
bibliography:
- "C:/Dropbox/localtexmf/bibtex/bib/statistics.bib"
- "C:/Dropbox/localtexmf/bibtex/bib/graphics.bib"
For the record: I raised this as an issue for pandoc-citeproc at https://github.com/jgm/pandoc-citeproc/issues/220
It turns out that there were problems in how pandoc-citeproc handles some characters in #{string={}} and non-ASCII characters in .bib files, so what I was trying now works, with hard-coded pathnames, in all the forms I tried.
To make it work more like processing of .Rnw files via Latex/bibtex it would be nice to be able to use something like
bibliography:
- `r system(kpsewhich statistics.bib)`
- `r system(kpsewhich graphics.bib)`
Those commands do find the right files in an R session, but not from a YAML header.
I'm using Rstudio to write an RMarkdown document that I turn into a PDF using MiKTeX on Windows through knitr and pandoc. LaTeX engine is xelatex.
My .Rmd file YAML header:
---
title: "My Title"
author: "Me"
geometry: margin=2cm
output:
pdf_document:
fig_caption: no
fig_height: 4
fig_width: 6
latex_engine: xelatex
html_document:
css: styles.css
keep_md: no
fontsize: 10pt
---
In the text I have
...parameter $\lambda=0.2$ with...
and I get "parameter = 0 2 with" -- both the lambda and even the dot are missing.
This line
mean of $\frac{1}{\lambda}=5$ of the
turns into
EDIT: When I try to add as an experiment (I'm on Windows)
mainfont: Arial
to the YAML header I get a pandoc error
! Undefined control sequence.
\fontspec_calc_scale:n ...ec_tmpb_dim }\fp_div:Nn
\l_fontspec_tmpa_fp {\l_fo...
l.18 \setmainfont{Arial}
pandoc.exe: Error producing PDF from TeX source
Error: pandoc document conversion failed with error 43
UPDATE:
Running pdflatex report1.pdf produces a correct PDF.
RStudio runs "C:/Program Files/RStudio/bin/pandoc/pandoc" report1.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash-implicit_figures --output report1.pdf --template "D:\Documents\R\win-library\3.2\rmarkdown\rmd\latex\default.tex" --highlight-style tango --latex-engine xelatex
So it seems the elsewhere recommended engine "xelatex" produces faulty output, while "pdflatex" works. Unfortunately I forgot the reasons given by some sources incl. SO that I followed a few days ago when switching to xelatex, I only remember it was highly recommended to use that with knitr in RStudio rather than pdflatex.
I'm posting this answer to increase the visibility of #user1983395 's comment regarding this error.
I was facing the same error as OP. pdflatex just produced the mentioned error, and xelatex produced an error whenever there was a call to a math formula ( $X_i$ or $$X_i$$ ).
After running C:\Program Files\MiKTeX 2.9\miktex\bin\x64\updmap.exe I was able to generate a pdf both with pdflatex and xelatex. Please notice that you may need to run it as administrator.