knitr

How can I set graphical parameters (par()) and structure options (strOptions()) in a knitr document?

冷暖自知 提交于 2019-12-22 05:23:20
问题 I am working on a knitr-sweave document and have found that global R options like par(lwd=3) and strOptions(strict.width='cut') do not take effect in later code chunks. I can specify these options as arguments each time I plot() or str(), so it's not a huge problem. I'm just wondering if anyone has any insight into this. Should I be caching the code chunk where I set these options? I call some libraries in early code chunks and set variables in others and they all seem to be accessible

Limit Output of Function in Rstudio (3.1.1) when Knitting to PDF

﹥>﹥吖頭↗ 提交于 2019-12-22 05:11:51
问题 I would like to limit the number of lines that are produced from a function when I knit my markdown document in R. I've looked around quite a lot but can't find a solution. My code is below, it gives 50+ lines of data when run. My goal is to only have 9 lines of code produced by the sedist function. ```{r, results=1:9} sedist(FILENAME, method="correlation") ``` I have tried using {r, message=1:9} , {r, Hide=1:9} , {r, height=1:9} , {r, results='hide'} and similar. 回答1: Something like this?? `

Limit Output of Function in Rstudio (3.1.1) when Knitting to PDF

☆樱花仙子☆ 提交于 2019-12-22 05:11:29
问题 I would like to limit the number of lines that are produced from a function when I knit my markdown document in R. I've looked around quite a lot but can't find a solution. My code is below, it gives 50+ lines of data when run. My goal is to only have 9 lines of code produced by the sedist function. ```{r, results=1:9} sedist(FILENAME, method="correlation") ``` I have tried using {r, message=1:9} , {r, Hide=1:9} , {r, height=1:9} , {r, results='hide'} and similar. 回答1: Something like this?? `

References page truncated in RMarkdown ioslides presentation

六眼飞鱼酱① 提交于 2019-12-22 05:01:14
问题 I prepare a ioslides presentation in RMarkdown via RStudio. As the presentation contains a lot of references they are truncated: With {.allowframebraks} there seems to be a quick solution for beamer presentations as this answer shows. Is there one for ioslides, too? 回答1: This isn't exactly what you're asking for, but it might be the best you can do. Insert the following inline CSS at the end of your document (i.e. just before where the references will be inserted), and instead of truncating

prevent knitr/Rmarkdown from interleaving chunk output with code

核能气质少年 提交于 2019-12-22 05:00:28
问题 When I use knitr to build an HTML document out of the following code: Chunk Output ======================================================== Outside a chunk. ```{r chunk1, results='asis'} cat('Inside a chunk\n\n') for (i in 1:3) { cat('* Inside loop #', i, '\n') } cat('Outside a loop, but still inside the first chunk') ``` Between chunks. ```{r chunk2, results='asis'} cat('Inside second chunk') ``` I get output where the code in chunk1 is interleaved with the output of the cat statements.

reusing chunks that include plotting with knitr .Rmd

空扰寡人 提交于 2019-12-22 04:55:28
问题 When a chunk that includes plotting is reused the plots are not referenced properly, i.e. they are identical for both chunks though they are supposed to be different. What can I do about it? ## Test ```{r} col <- "black" ``` ```{r chunk1} plot(0, col=col) ``` ```{r} col <- "red" ``` ```{r chunk1} ``` 回答1: You should use a different label like ```{r chunk2, ref.label='chunk1'} ``` See http://yihui.name/knitr/demo/reference/ 来源: https://stackoverflow.com/questions/11080793/reusing-chunks-that

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

杀马特。学长 韩版系。学妹 提交于 2019-12-22 04:38:07
问题 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

Reduce file size of R Markdown HTML output

早过忘川 提交于 2019-12-22 04:31:38
问题 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. 回答1: The html_vignette format is perfect if you want a smaller file size. As

Reduce file size of R Markdown HTML output

白昼怎懂夜的黑 提交于 2019-12-22 04:31:21
问题 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. 回答1: The html_vignette format is perfect if you want a smaller file size. As

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

旧巷老猫 提交于 2019-12-22 03:50:51
问题 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