Problem
I have a .Rmd template file which I currently use to render PDFs using rmarkdown::render.
I need the option to also render the .Rmd as a markdown file. I have tried setting output_format to md_document in rmarkdown::render however this produces a markdown file containing lots of html tags for the tables etc. I don't want any html; I need it to be readable in a console, with tables formatted using the markdown pipe styling.
What I've tried
I tried setting output_format to
output_format(knitr = rmarkdown::knitr_options(opts_knit = list(knitr.table.format = "pipe")),
pandoc = rmarkdown::pandoc_options(to = rmarkdown::rmarkdown_format())
but this style produces a markdown file with html tags instead of piped tables.
How do I set the markdown render settings to render as I need?
Perhaps try adding results='asis' to knitr opts
Related
I have created a large R Markdown document with many child docs using RStudio to produce output in both HTML and PDF.
I added this simple line to the YAML parameters of the document and it does exactly what I need. The entire doc is rendered and saved as both html and pdf output. Formatting of complex tables is preserved nicely.
knit: pagedown::chrome_print
BUT - the pdf is oversized. It simply needs to be scaled to 0.8 to be really useable. chrome_print documentation says that scale can be adjusted within the chrome_print command. I've tried this:
knit: pagedown::chrome_print(scale = 0.8)
which produces an Execution Halted error. I have tested other ways to pass parameters through the render to chrome_print, but none work.
The question is simple: Is there a way to pass parameters into the knit: pagedown::chrome_print operation?
After much experimentation, I find there is currently no way to adjust any pdf options from within R markdown YAML using knit: pagedown::chrome_print.
The workaround I've found is to use the code chunk below to render the Rmarkdown. It saves to both html and pdf formats and allows the user to assign filenames. Note that scaling does not adjust pagination nicely without CSS reset as shown. This works great, and allows full use of rmarkdown parameters and all chrome_print options.
fname = "OutputFilename"
pagedown::chrome_print(
rmarkdown::render(
input = "input.Rmd",
output_file = paste0(fname, ".html"),
output = paste0(fname, ".pdf"),
options = list(scale = 0.7, preferCSSPageSize = FALSE))
RMarkdown knitting creates beautiful html, including animated gifs with R codeblocks like:
{r, echo=FALSE, out.width="80%", fig.cap=""}
knitr::include_graphics(path="imagesForRmd/visualSearch/directionOfMotionPopsOut.gif")
While such codeblocks work for including images other than gifs in the PDF output of bookdown, animated gifs unsurprisingly yield an error:
Cannot find the file(s): "(imagesForRmd/visualSearch/directionOfMotionPopsOut.gif"
Is there a way to conditionally exclude specific content in my .Rmd files, such as the above codeblock, from the pdf_book and ePub rendering, so that the error does not occur? Then I could create the html version with the animated gifs, and the PDF and ePub without.
I think it's more idiomatic to do this using the chunk option eval. As already mentioned, using knitr you may check the output format on knitting. Since epub is considered an HTML output format you may do it like this:
```{r, eval = knitr::is_html_output(excludes = "epub")}
knitr::include_url(path = "your_image.gif")
```
```{r, eval = knitr::is_latex_output()}
knitr::include_graphics("your_image.png")
```
One solution is to write an if/else statement to display the animated GIF in the HTML book, and display a static PNG image in the PDF and other books:
if(knitr::is_html_output()) knitr::include_url("images/sample.gif", height = "250px") else knitr::include_graphics("images/sample.png")
I use rstudio to write r-markdown, but sometimes it is not compatible with markdown support by pandoc(math for example. If there is a way allow me to convert r-markdown to pandoc markdown, then it will be convenient to export my articles to pdf, org, rts, latex...
https://pandoc.org/ also seems doesn't mention rmarkdown support.
I have tried to export .html form rstudio and use pandoc convert the html file back to markdown, but it seems doesn't work.
Actually pandoc is used to create pdf and other formats from r-markdown. Therefore there is an intermediate file with pandoc compatible markdown. You could retain this file by:
rmarkdown::render("document.Rmd", output_format = "pdf_document", run_pandoc = FALSE)
I tried to use pander tables in a markdown page that is generated from R-markdown files like Yihui describes in an example page.
In my _config.yml I have the markdown type set to markdown: kramdown. I know that some things are different in this markdown type compared to the markdown knitr uses per default. So if I compile my page in RStudio with knitr the table looks alright. If I compile the page with jekyll the table looks not formatted right.
```{r key}
library(pander)
LETTERSplus <- c(LETTERS, "_", ".", ",", "-")
key <- sample(LETTERSplus)
names(key) <- LETTERSplus
pander(key)
```
Compiled with knitr inside RStudio it looks alright:
Compiled with Jekyll it looks like this:
I don't want to use kable since it formats the table differently and there is now column wrap if the table is too long.
Do I have to set some special pandoc options to make this work? Options to define the markup type pandoc has to output? I don't see any other options inside the pander() function.
I am working with markdonw v2, the rmarkdown package. Throughout the .Rmd file, I create links to websites or images
[Link1][pathLink1]
![Image1][pathImage1]
then, at the end of the document I give the references
[pathLink1]:http://website.com/linkes/Link1.md
![pathImage1]:./images_rmd/
There are other reports that talk about the same citation and use same images in different contexts. I would like to create a separate file containing all the links and path difinitions, so that I could simply source it at the end of each .Rmd file, like I would call in an R environment
source(/Rcode1.R)
Question: How do I "source" another file in .Rmd, so that the sourced code prints needed text strings into the .Rmd file?
This would offer some help with citations and scientific paper composition in HTML and PDF.
http://yihui.name/knitr/demo/child/
```{r child, child = '~/path/to/child.Rmd'}
```
and similarly for .Rnw files:
<<child, child = '~/path/to/child.Rnw'>>=
#
And a full example: https://github.com/yihui/knitr-examples/blob/master/087-child-example.Rnw