r-markdown

Automatically number sections in RMarkdown

混江龙づ霸主 提交于 2019-12-03 22:39:24
I am trying to create a report in R markdown that has sections ordered Section 1 Header 1.1 sub section 1 1.2 sub section 3 Section 2 Header 2.1 2.2 sub section 2.2.1 another sub section Is there a way get R markdown to generate an ordered list like this? Martin Schmelzer Add the option number_sections: true to your YAML header: --- title: "My Report" output: html_document: number_sections: true --- # Main Section ## 2nd Level ### 3rd Level And voilá, your sections are numbered: 来源: https://stackoverflow.com/questions/40120050/automatically-number-sections-in-rmarkdown

How do I produce R package vignettes in multiple formats?

孤人 提交于 2019-12-03 22:29:19
I use knitr and rmarkdown to write vignettes for R packages. Thanks to the magic of pandoc it is easy to turn these documents into a variety of formats. I would like to take advantage of this by offering vignettes as both HTML and PDF. There is support from rmarkdown to specify parameters for multiple output formats in the documents metadata block. For example, I might have something like this: output: html_document: standalone: true smart: true normalize: true toc: true highlight: tango self-contained: true theme: cerulean pdf_document: toc: true highlight: tango geometry: margin=2cm

Knit pdf from rmd script by clicking an executable r file

雨燕双飞 提交于 2019-12-03 20:05:22
问题 Synopsis I would like to produce a pdf file from an rmd script just by clicking a file / an icon so that my coworkers don't exhaust themselves by opening RStudio first. The question When I saw this on R-bloggers, and got it working, I thought I was approaching the perfect work flow from scripting to sharing my work by letting my coworkers execute a file and get a pdf with updated numbers as a result. However, I can't get it to work with some of the functions in the knitr library. Best case

Pretty print sql code from separate file with knitr

你离开我真会死。 提交于 2019-12-03 19:13:01
问题 Knitr produces a nice, syntax highlighted code when using a code chunk as below. ```sql SELECT column FROM table ``` Is it possible to achieve the same thing but with the sql code stored in a file? Something like: ```sql read_chunk('mycode.sql') ``` 回答1: I think you can use an inline R expression to achieve it: ```sql `r xfun::file_string('mycode.sql')` ``` 来源: https://stackoverflow.com/questions/24524594/pretty-print-sql-code-from-separate-file-with-knitr

Synchronizing two leaflet maps in R / Rmarkdown

旧巷老猫 提交于 2019-12-03 18:55:39
JS leaflet allows two maps to be synchronized . See an example of synchronized leaflet maps here . I would like to implement synchronized leaflet maps in R and more specifially in Rmarkdown/knitr . Preferably, the maps should shown next to each other horizontally (just like in the example ). Here is a minimal Rmarkdown ( .Rmd ) example of two maps I would like to sync. The solution does not have to be based on the the mapview package. Any solution is welcome really (-: --- title: "How to sync 2 leaflet maps" author: "me" date: "2 April 2016" output: html_document --- ```{r SETUP, include=FALSE

How to show code but hide output in RMarkdown?

只谈情不闲聊 提交于 2019-12-03 18:38:16
问题 I want my html file to show the code, but not the output of this chunk: ```{r echo=True, include=FALSE} fun <- function(b) { for(a in b) {print(a) return(a * a)} } y <- fun(b) ``` When I run the code, i need the print to see the progress (it is quite a long function in reality). But in the knitr file, I use the output in a further chunk, so I do not want to see it in this one (and there's no notion of progress, since the code has already been run). This echo=True, include=FALSE here does not

Including Bibliography in RMarkdown document with use of the knitcitations

蓝咒 提交于 2019-12-03 18:22:37
问题 I'm trying to use knitcitations and add bibliography to the R Markdown document that I'm drafting in R Studio. The header of my document looks like this: --- title: "Some Title" author: "Me" date: "September 2015" bibliography: bibliography.bib output: pdf_document: highlight: tango number_sections: yes toc: yes --- I want to add the bibliography at the end using the following code: ```{r generateBibliography, echo=FALSE, eval=TRUE, message=FALSE, warning=FALSE} require("knitcitations")

Conditionally include a list of child documents in RMarkdown with knitr

爱⌒轻易说出口 提交于 2019-12-03 17:50:36
问题 Given a list of child documents, how can you choose which to insert into a master document based on some criteria? In my use case, I am matching the unknown entries in one dataset to the desired entries in a second dataset. The second dataset has child documents associated with each entry. If a match is found, I want to include its associated child document. In its most basic form, this psuedo-code shows the gist of what I am trying to achieve (inspired by this question here): ```{r, eval

Create sections through a loop with knitr

你离开我真会死。 提交于 2019-12-03 17:26:06
See this reproducible example : --- title: "test" output: html_document --- ## foo ```{r} plot(1:3) ``` ## bar ```{r} plot(4:7) ``` ## baz ```{r} plot(8:12) ``` I want to be able to automate the creation of these sections as I can't know how many they will be before going further in my analysis. My input to get this would be : my_list <- list(foo = 1:3, bar = 4:7, baz = 8:12) my_fun <- plot my_depth <- 2 And the ideal answer (though I'm welcoming any improvement) would help me build a mdapply function so that I could just run: ```{r} mdapply(X = my_list, FUN = my_fun, title_depth = my_depth) `

Numbered Code Chunks in RMarkdown

橙三吉。 提交于 2019-12-03 17:20:42
Is there an option I can provide to code chunks in RMarkdown so that it will have a cell number attached to the HTML output. Much like Jupyter has cell numbers. I've seen some example with line numbering which is not what I want. Using cell numbers is helpful when I'm discussing an RMarkdown HTML file over the phone with someone. I can ask him/her to see cell 23 . I have a lot of R code, so providing section titles, while possible, is tedious. Here's a solution using only CSS . It relies on CSS counters : each new R chunk increments the counter (named counter-rchunks ). You can knit the