knitr

How to cache knitr chunks across two (or more) files?

半腔热情 提交于 2020-01-07 00:53:06
问题 I want to use some R-Code in two different *.Rnw files and want to use caching across those files. I read http://yihui.name/knitr/demo/externalization/ Caching in one file just works fine. But running the second one the whole code is executed again: plain.R ## @knitr random1 a <- rnorm(10) a doc1.Rnw (and doc2.Rnw) \documentclass{article} <<set-options, echo=FALSE, cache=FALSE>>= options(replace.assign=TRUE) opts_chunk$set(external=TRUE, cache=TRUE, echo=FALSE, fig=TRUE) read_chunk('plain.R')

Create PDF using Rhtml and iterate over data frame

谁说我不能喝 提交于 2020-01-06 20:24:46
问题 I have a data frame that has demographic information split into 16 groups. I basically need to iterate over these groups and create a PDF page for each group. I've tried using Rhtml but so far I can only get one page to generate. Is there a way to use templates or something? 回答1: When you need PDF output, why don't you directly compile .Rnw to .pdf ? Here an example using the iris dataset. It prints the first few rows of each species on a new page: \documentclass{article} \begin{document} <

Create PDF using Rhtml and iterate over data frame

大憨熊 提交于 2020-01-06 20:24:11
问题 I have a data frame that has demographic information split into 16 groups. I basically need to iterate over these groups and create a PDF page for each group. I've tried using Rhtml but so far I can only get one page to generate. Is there a way to use templates or something? 回答1: When you need PDF output, why don't you directly compile .Rnw to .pdf ? Here an example using the iris dataset. It prints the first few rows of each species on a new page: \documentclass{article} \begin{document} <

knitr templating - Dynamic chunks issue

谁说胖子不能爱 提交于 2020-01-06 14:40:39
问题 The following code is a very simplified MRE for an issue I'm experiencing. I'm trying to avoid R template packages, such as brew , and only use knit_expand() to achieve my goals. The issue is twofold: generated chunks don't get parsed (this is not happening in my real code, but happens in MRE) instead of LaTeX \includegraphics , knitr (or rmarkdown , or pandoc ) generates RMarkdown syntax for inserting figures ( ![] ). In regard to the former, I have a feeling that it might be related to my

Getting example codes of R functions into knitr using helpExtract function

青春壹個敷衍的年華 提交于 2020-01-06 08:49:12
问题 I want to get the example codes of R functions to use in knitr . There might be an easy way but tried the following code using helpExtract function which can be obtained from here (written by @AnandaMahto). With my approach I have to look whether a function has Examples or not and have to include only those functions which have Examples. This is very inefficient and naive approach. Now I'm trying to include only those functions which have Examples. I tried the following code but it is not

How to change Sys.setlocale, when you get Error “request to set locale … cannot be honored”

你说的曾经没有我的故事 提交于 2020-01-06 07:54:36
问题 This relates to the problem I'm trying to resolve here: Printing UTF-8 (Russian) characters in R, Rmd, knitr. I was told that this problem does not exist if native locale was en_US.UTF-8 . (My current native locale is English_Canada.1252 .) But I cannot just simply change my English_Canada.1252 to en_US.UTF-8. - When I try I get this error message: > Sys.setlocale("LC_CTYPE", "en_US.UTF-8") OS reports request to set locale to "en_US.UTF-8" cannot be honored[1] "" Any idea how to resolve it?

Rmarkdown Fatal error: creating temporary file for '-e' failed Mac sudden error

柔情痞子 提交于 2020-01-06 06:58:38
问题 I've been able to knit my markdown files fine until today, and now I'm getting the error Fatal error: creating temporary file for '-e' failed I've looked all over and there doesn't seem to be an easy fix. I've updated R and Studio, closed everything down and reopened it to no avail. My session info R version 3.6.1 (2019-07-05) Platform: x86_64-apple-darwin15.6.0 (64-bit) Running under: macOS Mojave 10.14.6 Matrix products: default BLAS: /System/Library/Frameworks/Accelerate.framework/Versions

how to colour different Rmarkdown kable tables in different colour

≯℡__Kan透↙ 提交于 2020-01-06 01:57:45
问题 Below is the code I am using. Only problem is that both my tables are of same colour which is my second colour code (#ffff99). How can I keep the background of both tables different. <style> table { background-color:#eff8e5; } </style> ``` {r} kable(df1) ``` <style> table { background-color:#ffff99; } </style> ``` {r} kable(df2) ``` 回答1: HTML/CSS is not rendered the way you implicitly assume. Your code would work as expected if the rendering followed a procedure like: set: "tables are green"

Lyx+knitr code externalization with read_chunk('foo.R') fails

拥有回忆 提交于 2020-01-05 09:34:00
问题 I am trying to use read_chunk() to separate my R code from my Lyx file as explained here. My Lyx setup compiled the knitr_minimal.pdf from knitr_minimal.lyx without any issues. But then I tried to replace this: <<boring-random>>= set.seed(1121) (x=rnorm(20)) mx <- mean(x) vx <- var(x) @ The first element of x is \Sexpr{x[1]}. Its mean is \Sexpr{mx}. with this: <<boring-random, cache=FALSE>>= read_chunk('minimal.R') @ The first element of x is \Sexpr{x[1]}. Its mean is \Sexpr{mx}. The script

R Blogdown: insert images side by side using knitr

徘徊边缘 提交于 2020-01-05 09:14:23
问题 I am working on a personal website using blogdown. I know about the handy addin for inserting an image - it works well, but for only one image. Is there a way, using knitr::include_graphics , to insert multiple images side-by-side? I'm aware of using something like this: ![image text](path/to/image.png) ![other image text](path/to/image2.png) But this cannot adjust the size of each image, which is an important formatting option for me. Note: While poking around for a solution before I post