knitr

Using knitr to produce complex dynamic documents

放肆的年华 提交于 2019-12-11 03:48:52
问题 The minimal reproducible example (RE) below is my attempt to figure out how can I use knitr for generating complex dynamic documents , where "complex" here refers not to the document's elements and their layout, but to non-linear logic of the underlying R code chunks. While the provided RE and its results show that a solution , based on such approach might work well, I would like to know : 1) is this a correct approach of using knitr for such situations; 2) are there any optimizations that

Use R code or Windows user variable (“%userprofile%”) in YAML?

吃可爱长大的小学妹 提交于 2019-12-11 03:48:29
问题 In my yaml call I have --- title: "`r paste0('Test. Done ', format(Sys.Date(), '%B-%Y'))`" output: word_document: fig_caption: yes fig_height: 4 fig_width: 7 reference_docx: %userprofile%\Documents\template.docx --- But YAML complains about %userprofile% . Is it possible to include such a variable? I have tried e.g. reference_docx: "`r file.path(path.expand('~'), 'skabelon.docx')`" But that still results in this YAML error. pandoc.exe: `r file.path(path.expand('~'), 'skabelon.docx')`:

Is there a way to specify a global options chunk function in Rmarkdown so that only some of the graphs will show/not show by toggling the command?

自闭症网瘾萝莉.ら 提交于 2019-12-11 03:41:27
问题 I currently have a subset of figures in Rmarkdown but would like to hide or display them by specifying echo = F or echo = T for those only. It is tedious to go through each of the figures I want to hide or display and change the echo option. Is there a global way of toggling or making certain figures show? In other words, is there a way to perhaps do: ```{r, echo.func} include.graphics("this/plot/shows.jpg") ``` and be able to somehow control echo.func to be equal to echo = F or echo = T in

consistent code html inline and in chunks with knitr

回眸只為那壹抹淺笑 提交于 2019-12-11 03:39:54
问题 I would like the code in paragraphs to be consistent with the code shown in code chunks. For example: <p> The formula method for a linear model is <code>lm(y~x, data = dat)</code>. For our data the results are: </p> <!--begin.rcode lm(y~x, data = dat) end.rcode--> It would be nice to use something besides <code> inline and get the same formatting as the chunk's code. I'm using knitr : > sessionInfo() R version 3.0.1 (2013-05-16) Platform: x86_64-apple-darwin10.8.0 (64-bit) locale: [1] en_US

bookdown/rmarkdown/knitr: Open a document with the (graphical) result of a later code chunk?

痴心易碎 提交于 2019-12-11 03:35:32
问题 Imagine a simplified bookdown / rmarkdown document that goes something like this: --- title: "Test Doc" author: "Balin" date: "May 25, 2018" output: bookdown::pdf_document2: toc: no --- ```{r setup, include=FALSE} knitr::opts_chunk$set(echo = TRUE) ``` <!-- Placeholder - See question --> This stands in for an extensive report where `code`, its documentation and interpretation of its results are integrated: 1. We load some data: ```{r data-loading} my_data <- cars ``` 2. We (rougly) explore

How do I set up mirror margins in R markdown using knitr

纵饮孤独 提交于 2019-12-11 03:13:52
问题 I know how to adjust the margins in an r markdown pdf file with the following: --- title: "Model 1 Coefficients" output: pdf_document geometry: margin=1in --- But I would like to make it so that the margin sizes switch between even and odd pages so that the inner margin is always 1.25 in and outer is always .25 in. I was able to find some latex info on this website http://texdoc.net/texmf-dist/doc/latex/geometry/geometry.pdf and it seems like I want to use the twoside option but I'm not sure

using .Last.value in rmarkdown/knitr

核能气质少年 提交于 2019-12-11 03:08:08
问题 Having and Rmd file with below content: ```{r} data.frame(a=1) str(.Last.value) ``` It renders data.frame but rendering str(.Last.value) produces ## NULL . Is there any knitr option or a trick I can use to make it works as expected? Expected output from the second ## 'data.frame': 1 obs. of 1 variable: ## $ a: num 1 回答1: Actually, there is a way to make .Last.value to work. ```{r setup, include=FALSE} knitr::opts_chunk$set(render = function(x, ...){ unlockBinding(".Last.value",

Change size of individual ggplot2 charts in knitr pdf file

亡梦爱人 提交于 2019-12-11 03:05:38
问题 How can I modify the height and width of individual charts produced by ggplot2 in a knitr output pdf? In other words, not using the fig.height and fig.width in the code chunk options. I have some charts that work best at one size and others that need to be a different size. 回答1: Here is an example .Rmd file to show how to do this. It would be preferable to use a 'setup' chunk to loaded and attached namespaces, and to set options. Each chunk can have its own set of options which will take

How to specify a customized paper size in r markdown

不问归期 提交于 2019-12-11 03:02:43
问题 I am using R Markdown to produce a booklet with specific height and length measures. Is there a way to specify to R Markdown to produce the article in 5.5"x8.5" measures. I saw questions asked about producing A4 size pdf here but that does not help as my measure is very specific. 回答1: Use the geometry option in the YAML (which becomes options to the geometry package in LaTeX). For example: --- title: "Title" author: "Me" geometry: paperheight=8.5in,paperwidth=5.5in,margin=1in output: pdf

Trying to set Knitr 'document' output hook results in code chunk line breaks being lost

半世苍凉 提交于 2019-12-11 02:51:59
问题 I've been reading all the documentation and examples I can find for Knitr's output hooks for editing the output of the document. I'm using Knitr to process a .Rmd file, which looks like this: [SOME_SHORTCODE_TO_BE_REPLACED] (I eventually want this to be replaced by Knitr when it parses the document) ```{r echo=TRUE, eval=FALSE} data1 <- rnorm(10, mean = 0, sd = 10) data2 <- rnorm(10, mean = 2, sd = 2) model <- lm(data1 ~ data2) summary(model) ``` If I run opts_chunk$set(tidy = FALSE) knit