knitr

RStudio, knitr, pandoc, Word: how do I get a 'new page' in my docx?

拟墨画扇 提交于 2019-12-05 01:45:14
I am using the RStudio, knitr, pandoc, MS Word combo to get my final results in a docx document. Occasionally, I would like the report to continue on a new page. I can't find the way to achieve this. From what I have Googled, it seems to be possible with CSS . I don't know HTML or CSS , but if it is the solution I will learn. Just don't want to take the wrong road... Try the LaTeX command \newpage. Pandoc recognizes it and might (not on a computer right now) translate it to a Word page break. ​```{=openxml} <w:p> </w:pPr> <w:r> <w:br w:type="page"/> </w:r> </w:p> ​``` Insert this codes in the

How to best generate multiple HTML files from RMarkdown based on one dataset?

試著忘記壹切 提交于 2019-12-05 01:39:20
问题 I have an RMarkdown report that is very useful and has grown to be several pages long with all the figures and tables in the HTML file. It uses the same dataset for all the figures and tables. What I would like to do is to keep generating this large html file and then several new subdirectories, each with their own html files and subdirectories within those, each with their own html files. In this case, the full report contains data on a department, then each subdirectory would contain an

How to control knitr kable scientific notation?

自闭症网瘾萝莉.ら 提交于 2019-12-05 01:31:45
I have a data frame like this: > summary variable value 1 var1 5.810390e-06 2 var2 5.018182e-06 3 var3 5.414286e-06 4 var4 3.000779e+02 5 var5 -2.105123e+01 6 var6 8.224229e-01 I want to print it in a word document using knitr/kable. Thus I used the following function: knitr::kable(summary, row.names = FALSE, col.names = c("Variable", "Mean")) But the result is not satisfying: I'm OK with variables 4 to 6, but variables 1 to 3 are really not easy to read this way... Is there a way to control this format? The most general way is to do the formatting yourself, and send a dataframe of character

LaTeX math expression in knitr kable (Sweave)

余生颓废 提交于 2019-12-05 01:17:58
Is it possible and how to use a LaTeX math expression in a knitr/Sweave report with kable ? In the example below, $x^2$ is rendered "as is". With xtable , for the example below, I would use the option sanitize.colnames.function = function(x) x of print.xtable . Is there such an option for kable ? \documentclass{article} \usepackage{booktabs} \begin{document} <<>>= library(knitr) dat <- mtcars[1:5,1:5] options(knitr.table.format = "latex") @ <<results='asis'>>= names(dat)[1] <- "$x^2$" kable(dat, booktabs=TRUE, caption="My table") @ \end{document} Yes, use the option escape=FALSE : kable(dat,

Programmatically insert header and plot in same code chunk with R markdown using results='asis'

风流意气都作罢 提交于 2019-12-05 00:58:49
The results = 'asis' chunk option within Rmarkdown allows one to easily dynamically create text including headers. However, I wish to dynamically create a header with the asis option, but then in the same code chunk insert some graphics. The most related answer I could find for this is here: Programmatically insert text, headers and lists with R markdown , but the answer to this question does not allow both dynamic headers and plots within those dynamic headers. Here is a simple reproducible example follows demonstrating what I can and cannot achieve with results = 'asis' The code directly

multi-line equation in RMarkdown

感情迁移 提交于 2019-12-05 00:56:20
I am trying to create a multi-line equation in RMarkdown. I have tried the following code, extracted from http://www.rstudio.com/ide/docs/authoring/using_markdown_equations , $$ \begin{aligned} \dot{x} & = \sigma(y-x) \\ \dot{y} & = \rho x- y - xz \end{aligned} $$ however the knitred HTML document gives a single-line equation: This code produced 2 HTML lines, as desired, when cut and paste into RStudio in Windows 7 with knitr. If the second slash at the end of the 3rd line was removed, it produced the result shown in example. 来源: https://stackoverflow.com/questions/21126776/multi-line-equation

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

霸气de小男生 提交于 2019-12-05 00:39:47
问题 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. 回答1: Try putting this code chunk at the beginning of the Rmd document. ```{r setup, cache=FALSE, include=FALSE} library(knitr) output <- opts_knit$get(

Conditionally evaluate heading using knitr in .Rmd file

不羁岁月 提交于 2019-12-05 00:35:44
问题 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) ``` 回答1: 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

How to make scrollable slides in an ioslides presentation with rmarkdown

两盒软妹~` 提交于 2019-12-05 00:15:44
I am using RMarkdown to create an ioslide presentation with shiny. Some of my slides do not actually fit on one page and are truncated. Since this is a HTML output, I would like to add a scroll bar to make my long slides scrollable. I have been googling a lot and found a partial solution to make R code chunks scrollable . However I want to make my slides scrollable regardless of the content. This is a toy Rmd example giving slides not fitting on one page: --- title: "Untitled" date: "30 October 2018" output: ioslides_presentation runtime: shiny --- ```{r setup, include=FALSE} knitr::opts_chunk

How do you hide and pass variables in knitr child documents?

℡╲_俬逩灬. 提交于 2019-12-05 00:08:27
knitr makes PDFs out of code that is a combination of (in my case) R and LaTEX. One can assemble a document out of child documents. As I use it right now, the document is assembled out of global variables, passed into and out of every child document. This makes it easy to produce spaghetti code. Is there any way to make R variables "local" to a child doc? How about make exporting of variables explicit? I could NULL out every local variable at the end of a child doc, but I wonder if there is some reasonable formal mechanism for loosening code coupling between child documents. knitr evaluates