r-markdown

Using R-markdown knitr hooks to custom format tables in HTML reports

本秂侑毒 提交于 2019-12-05 05:17:20
I am trying to set up a knitr::knit_hooks() to automatically format data frame output of an R-markdown chunk with kableExtra in my HTML report. I would like to not repeatedly add the following lines (or any lines) to the end of each chunk of tabulated data: head(iris) %>% kable("html") %>% kable_styling("hover", full_width = FALSE) I came up with one solution based on this answer that works by evaluating the chunk source (see my answer below that includes some issues that I have with this approach); I'm hoping there might be a better solution using the chunk output . Here is an example .Rmd

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

Numbered Code Chunks in RMarkdown

蹲街弑〆低调 提交于 2019-12-05 02:12:33
问题 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. 回答1: Here's a solution using only CSS . It relies