knitr

How to set knitr chunk output width on a per chunk basis?

萝らか妹 提交于 2019-12-03 17:30:55
问题 My question(s): Does knitr have an option that allows one to set R's width option on a per chunk basis? If not, is there a good reason (i.e. one rooted in some fundamental limitation of the knitr model) that it does not? What I've tried: To show what I'm wishing for, here is a hand-rolled hook function that does basically what I want. (I don't really like it though, (a) because it is ugly, relying on assignment of the variable .width into the global environment, and (b) because it's not

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) `

Converting Markdown to HTML5 slides via Pandoc through knitr in R

為{幸葍}努か 提交于 2019-12-03 17:20:37
Since version 1.2 knitr has a new function pandoc to convert markdown document to other formats via pandoc directly in R ( See here ). For example library(knitr) pandoc('foo.md', format='html') # HTML I wonder how to convert Markdown document ( See knitr-slides.md for MWE ) to HTML5 slides. Thanks First, add the following to your .Rmd document: <!--pandoc s: S: i: mathjax: --> Then use the command library(knitr) knit("foo.Rmd") pandoc("foo.md", format="dzslides") This will still create the file foo.html , but will use the pandoc command pandoc -s -S --mathjax -f markdown -t dzslides -o foo

Conditional formatting of a table in RShiny

℡╲_俬逩灬. 提交于 2019-12-03 15:18:44
I'm trying to visualize a cohort analysis, and wanted to use RenderDataTable in shiny to get this sort of a visualization where I would be able to highlight all the cells based on a separate column having values 1/0, with 1 being shaded and 0 not being shaded. I Tried a couple of things, including trying to use geom_tile in ggplot2 , but it was of no avail. I also tried looking at rpivotTable , but I wasn't able to figure out how to shade certain cells. Example Data: df <- " cohort wk value flag 1 1 24 0 1 2 12 0 1 3 10 0 1 4 5 0 1 5 2 0 2 1 75 0 2 2 43 1 2 3 11 0 2 4 14 0 3 1 97 0 3 2 35 0 3

Conditionally evaluate heading using knitr in .Rmd file

眉间皱痕 提交于 2019-12-03 15:11:15
Is it possible to conditionally evaluate a code chunk and its associated heading using R Markdown and knitr ? For example, if eval_cell is TRUE include the chunk and its heading, but don't include either if eval_cell is FALSE . ```{r} eval_cell = TRUE ``` # Heading (would like to eval only if eval_cell is TRUE) ```{r eval = eval_cell} summary(cars) ``` You can put the heading in an inline R expression: ```{r} eval_cell = TRUE ``` `r if (eval_cell) '# Heading (would like to eval only if eval_cell is TRUE)'` ```{r eval = eval_cell} summary(cars) ``` This will become cumbersome if you have large

Create index of definitions / theorems at end of bookdown book

烂漫一生 提交于 2019-12-03 14:48:27
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 == 'definition') is my friend. So I can do this anywhere in the end of the book, usually at the end: ```

How to set different global options in knitr and RStudio for word and html?

与世无争的帅哥 提交于 2019-12-03 14:42:31
I am using RStudio 0.98.932 and knitr 1.6. Would like to set different global knitr options for word and html. For example, want to set fig.width and fig.height as 6 for word and 11 for html. I can write some codes to switch the setting if it is available for the output format of a rmd file. How should I do this? Thanks for any suggestions. jlhoward Try putting this code chunk at the beginning of the Rmd document. ```{r setup, cache=FALSE, include=FALSE} library(knitr) output <- opts_knit$get("rmarkdown.pandoc.to") if (output=="html") opts_chunk$set(fig.width=11, fig.height=11) if (output==

R knitr markown: Setting HTML page width

老子叫甜甜 提交于 2019-12-03 14:21:50
I am using knitr to create a HTML webpage. The default setting seems to be 800px but I need a larger page size of 1100px body { max-width: 800px; margin: auto; padding: 1em; line-height: 20px ; } I have tried: library("markdown") library("knitr") knit2html("test.Rmd",options = c(width=1100)) But this still gives me the smaller page size of 800px How can I set the code for the HTML page width? csgillespie Add a css element to your document, e.g. --- title: "test" output: html_document: css: "test.css" --- and then put your new css information in that file, e.g. body { max-width: 1100px; margin:

“long vectors not supported yet” error in Rmd but not in R Script

戏子无情 提交于 2019-12-03 14:21:12
问题 I am operating matrices with R 3.1 and RStudio 0.99. I have my R Script and with cmd+enter it works without problem. I created an Rmd for reporting but I have this error Error in lazyLoadDBinsertVariable(vars[i], from, datafile, ascii, compress, : long vectors not supported yet: ../../../../R-3.3.1/src/main/connections.c:5600 Calls: <Anonymous> ... <Anonymous> -> <Anonymous> -> lazyLoadDBinsertVariable Execution halted Is there a way to bypass that error? This seems to be a dupicate of Large

Mass create documents in R markdown

ぃ、小莉子 提交于 2019-12-03 14:10:49
I'm wondering if anyone can help me with a dilemma I'm having. I have a dataset of around 300 individuals that contains some basic information about them (e.g. age, gender). I want to knit a separate R markdown report for each individual that details this basic information, in Word format. And then I want to save each report with their unique name. The actual code which sits behind the report doesn't change, only the details of each individual. For example: Report 1: "Sally is a female who is 34 years old". (Which I would want to save as Sally.doc) Report 2: "Mike is a male who is 21 years old