knitr

include images programmatically in .md document from within R chunk using knitr

依然范特西╮ 提交于 2020-01-01 09:50:34
问题 I want to programmatically include a lot of images in my .Rmd markdown document. Something like ```{r echo=FALSE} cat("![](myfile_1.png)") ``` will not work, as the resulting .md output is ``` ## ![](myfile_1.png) ``` I would need to get rid of the code tags ``` and the leading ## . Is there an option to directly inject markdown code from within the R chunk? BTY: The same issue applies to HTML as well. Here also a HTML code injection from within an R chunk would be really helpful. 回答1: Using

rmarkdown: how to use multiple bibliographies for a document

跟風遠走 提交于 2020-01-01 09:43:19
问题 [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

How to use Cairo PNGs in R Markdown

好久不见. 提交于 2020-01-01 08:44:49
问题 There are many advantages to using Cairo to save R graphics (see here, for example). When saving PDFs, for instance, the cairo_pdf device correctly embeds custom fonts. Using the cairo_pdf graphics device is easy with ggplot-based graphics with ggsave() : library(ggplot2) ugly_plot <- ggplot(mtcars, aes(x = wt, y = mpg)) + geom_point() + labs(title = "Some data about cars") + theme_gray(base_family = "Papyrus") ugly_plot ggsave(ugly_plot, filename = "ugly_plot.pdf", width = 4, height = 2.5,

Embed Rmarkdown with Rmarkdown, without knitr evaluation

我与影子孤独终老i 提交于 2020-01-01 08:02:31
问题 I want to demonstrate how to write RMarkdown, where said RMarkdown demonstration is embedded within an RMarkdown document used to create the course material. Within this fenced code block, I don't want knitr to execute the chunk. I want to put something like this into my "top level" Rmarkdown document, and have everything that's between the outer fences be printed verbatim in fixed width in the output HTML document, rather than having knitr evaluate the inner embedded R code chunk and inline

How to wrap code and the output in markdown (.Rmd)

烈酒焚心 提交于 2020-01-01 07:59:47
问题 In my documents in r parts I use long codes like: ```{r} output <- "very long query for example url to some website............................................." output ``` Is there any way not to make R wrap the code automatically, let's say after 60 characters? I tried tidy=TRUE, tidy.opts=list(width.cutoff=60) option but it doesn't work. And I want the same with output, because the output of my query is some text. I want to display the whole content in many lines, not just the begining in

latex kable side-by-side tables “Not in outer par mode”

倖福魔咒の 提交于 2020-01-01 07:30:38
问题 I am trying to create a page with side-by-side tables. I used other SO answers to do this for a simple table ```{r start-block, include=F,echo=F} library(dplyr) library(knitr) library(kableExtra) ``` ```{r sample, echo=FALSE, results='asis'} t1 <- kable(head(mtcars)[1:3], format = "latex", booktabs = TRUE) %>% kable_styling(latex_options = c("striped"), font_size=5) t2 <- kable(head(mtcars)[4:6], format = "latex", booktabs = TRUE) %>% kable_styling(latex_options = c("striped"), font_size=5)

Create index of definitions / theorems at end of bookdown book

别说谁变了你拦得住时间么 提交于 2020-01-01 05:18:31
问题 For reader convenience, I'd like to include, at the end of my bookdown book, written in markdown, a simple list or index of definitions from the body of the book. i.e. ones created using custom blocks, like this: ```{definition, bar, echo=T} A bar is defined here as a foo-like thing. ``` (My need is for definitions, but others might like lists of theorems, etc. Don't know if lists of figures and tables could be covered in the same way?) Thanks to @yihui I know that knitr::all_labels(engine ==

R & Knitr html output: Create collapsing and expanding header

余生颓废 提交于 2020-01-01 05:07:06
问题 Use case I use R and Knitr a lot to produce long html reports. The reports contain headers by using the markdown # syntax. These headers give good orientation for the reader's navigation... Problem ... but the reports sometimes get very long. Scrolling from beginning to the end take very long time. Readers of the reports get annoyed seeing all the report content before reaching the relevant parts. Question Is there a way to implement in Knitr a collapsing and expanding header element?

Include a specific chunk from one markdown document in another document

随声附和 提交于 2020-01-01 05:05:51
问题 I want to include the code from a specific chunk of a one markdown document into a second markdown doc. I want to do it by referring to the chunk by name (no hacky references to line-numbers, please). I don't want to run all the code in the child because some of it is rather time-consuming. Here's what I've tried. We have read_chunk for including plain R script in markdown docs. There is run_chunk but it's not clear if this can be used with external docs (I haven't had any luck so far). And

knit_child in a Rmd file is printing unwanted output

好久不见. 提交于 2020-01-01 05:01:20
问题 I had succesfully used knit_child for generating pdf files, following the code of http://yihui.name/knitr/demo/child/, but when I try to use that example in a .Rmd file: ```{r, results='asis', echo=FALSE, message=FALSE} out = NULL for (p in c("p1","p2","p3","p4","p5","p6","p7","p8","p9","p10")) { out = c(out, knit_child('quick_variable.Rmd')) cat(out) } ``` (I modify the original code, for work in Rmd ). I have two problems, the first one: | | | 0% | |... | 5% ordinary text without R code | |