knitr

Set code background colour in R markdown to PDF

邮差的信 提交于 2019-12-05 05:07:02
When an Rnw file is converted to PDF with RStudio and knitr , the code blocks have a pleasant grey background colour (like they do here at SO). When I convert a md file to PDF , the background colour is white and I can't seem to change it. The knitr code decoration option background is only for LaTeX and has no effect in md . How can I set a background colour for code blocks in the PDF I get from my md file? I see in some related questions that editing the markdown.css file might be relevant, but I'm not sure if that applies here since there's no html file in between the md and PDF files. This

how do you color the cell in rmarkdown pdf output

∥☆過路亽.° 提交于 2019-12-05 04:39:52
I cannot get cellcolor to work in rmarkdown: --- header-includes: - \usepackage{colortbl} - \usepackage{color} output: pdf_document --- ```{r, results="asis"} library(xtable) # Your data tab = data.frame(category = c("A","B","C"), groupA = c(.2,.3,.5), groupB= c(.6,.7,.9)) # Function to cut your data, and assign colour to each range f <- function(x) cut(x, c(0, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, Inf), labels=c("green", "red", "blue", "orange", "yellow", "purple", "brown", "white"), include.lowest = FALSE, right = TRUE) # Apply function to columns: this overwrites your data tab[c("groupA",

Change default alignment in pander (pandoc.table)

ぐ巨炮叔叔 提交于 2019-12-05 04:23:00
I am currently switching to pander for most of my knitr-markdown formatting, because it provides such great pandoc support. One of the things I am not so happy with is the default center-alignment. Marketing people may love it, but for technical reports it is an horror. The best choice used by Hmisc is to use left alignment for texts and dates by default, and right alignment for number of all type. Is there a simple way to get this globally set in pander ? library(pander) pander(data.frame( name = letters[1:3], size = 1:3, we.have.dates = Sys.Date() - 1:3 )) Thanks for you kind words and great

Knitr preamble error results in “pandoc document conversion failed with error 43”

痞子三分冷 提交于 2019-12-05 04:12:19
Rstudio Version 0.99.441; Windows 7 enterprise; knitr 1.10.5; MiKTex 0.4.5 r.1280 (2.9 64-bit) I have a an error on my office computer when trying to knit PDF's in Rstudio, there are no problems knitting to HTML or word. The problem may be related to updates because knitting used to work fine and my home computer can knit to pdf without issue, however I took my computer home to update and the problem is still there. My error message was as follows "pandoc.exe: Error producing PDF from TeX source Error: pandoc document conversion failed with error 43" I created a new file using the template

knitr::kable is there a way to reduce the font size?

淺唱寂寞╮ 提交于 2019-12-05 03:29:31
I am using this code chunk ```{r, echo = FALSE} knitr::kable(df) ``` However I would like to reduce the size of all font inside this table so that the output looks nicer. Is there a way to do that with kable or is there another package which supports it? You can also try library(kableExtra) . It has a lot of options to customise the table. Specifically, for font size: https://haozhu233.github.io/kableExtra/awesome_table_in_html.html#font_size df %>% kable("html") %>% kable_styling(font_size = 7) I use \tiny before the function and \normalsize after it, which works for .pdf using the formats

Can't change params in Rmd documents

冷暖自知 提交于 2019-12-05 03:08:23
As explained on this site it is possible to define parameters in the YAML header of a Rmarkdown file and the default values specified there can be overwritten with rmarkdown::render("foo.Rmd", params = list(param1 = "bar") . However when I try this I get the following error: params object already exists in knit environment so can't be overwritten by render params Here is a minimal reproducible Rmd document. Let's say the file name is test.Rmd . --- title: "Test" output: pdf_document params: name: Andreas --- Hello, my name is `r params$name`. When I now try rmarkdown::render("test.Rmd", params

Reduce file size of R Markdown HTML output

拟墨画扇 提交于 2019-12-05 02:42:51
If I create a very basic R Markdown file with no images or code and knit this HTML, I end up with an outputted file size that is more than 700kb in size. Is there any way to reduce the HTML file size? Minimal Example: --- title: "Hello world!" output: html_document: default html_notebook: default --- Nothing else to say, really. The output file from html_document is 708.6 kb in size, while html_notebook is 765.7 kb. The html_vignette format is perfect if you want a smaller file size. As described in the function documentation: A HTML vignette is a lightweight alternative to html_document

rmarkdown::render_site() Error in rmarkdown::render_site() : No site generator found

Deadly 提交于 2019-12-05 02:32:40
I am trying to knit together 3 files using this example: http://rmarkdown.rstudio.com/rmarkdown_websites.html My files all share the same directory, which has been set in the RStudio build options. I literally copied the YML from the examples with my own file names. Even if I copy the examples directly, I get the same error. I even ran the site_generator function from the RMarkdown Github: https://github.com/rstudio/rmarkdown/blob/master/R/render_site.R#L157 I noticed there are options for custom generators, which I do not want. All I would like to do is be able to knit together several

Create sections through a loop with knitr

半世苍凉 提交于 2019-12-05 02:27:10
问题 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

Synchronizing two leaflet maps in R / Rmarkdown

北城以北 提交于 2019-12-05 02:11:27
问题 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