knitr

How do I document parallel computations within knitr implemented in Rstudio?

这一生的挚爱 提交于 2020-01-05 09:04:40
问题 I'm coding an agent-based simulation. I plan to run parallel instances of the simulation to reduce computing time. I will use the parallel package. I want to document my code using knitr. Before I start, I'd like to confirm whether there will be any issues running the parallel package's functions from within a Markdown or Sweave document that I compile with knitr. 回答1: It works... Parallel Example in RStudio as run via knitr after being written in R markdown... ```{r parallel-do} library

knitr/pandoc: article template supporting keywords: and linespacing:

怎甘沉沦 提交于 2020-01-05 03:43:29
问题 I'm using the latest R Studio, R 3.2.5, rmarkdown 0.9.6, which comes with pandoc 1.15.2 to write a journal article. Submission requires: linespacing: 1.43 and a keywords: line just below the abstract. When I click Knit PDF I get the default template "C:\R\R-3.2.5\library\rmarkdown\rmd\latex\default-1.15.2.tex" which does not support these fields in the YAML header. I see that default-1.17.02.tex supports linespacing: , but not keywords: . I tried to modify the latter template to add keywords

Split r chunk header across lines in knitr

岁酱吖の 提交于 2020-01-05 03:39:50
问题 When I'm inserting long captions and the like in my R chunk header, it'd be nice to be able to split the header across multiple lines. Is there any easy way to do this? E.g.: ```{r, echo=FALSE, warning=FALSE, fig.cap="Here is my really long caption. It'd be nice to split this and other portions across lines"} print(plot(x=runif(100),y=runif(100))) ``` 回答1: No, you cannot insert line breaks in chunk options. From the manual: Chunk options must be written in one line; no line breaks are allowed

Format table of percentages in R

左心房为你撑大大i 提交于 2020-01-05 01:38:24
问题 I want to take a table of percentages, format the values as percentages and display them in a nice format. I'm using RStudio and knitting to PDF if that matters. I have seen other posts about this, but none of them seem clean, and don't really work well. For instance, the apply statement below does format as percent, however, it strips the years off, and surrounds the table in quotes. I can fix the quotes by using kable, but it just seems like this is a common enough problem that there is a

Using header of chunk to save plot

孤街浪徒 提交于 2020-01-04 15:14:47
问题 So I've been searching for an answer for this, and haven't really found anything. I'm hoping there isn't anything like this already on the board so I don't waste anyone's time. In the recent upgrade of I'm assuming RStudio, a method I used to save plots went away. Below is an example chunk of what it looks like: ```{r dummy, dev=c('png', 'pdf'), fig.height=4, fig.width=6} x = 1:10 y = 10:1 plot(x,y) ``` The code will still compile when I do this. However, when I knit my code in order to save

Using header of chunk to save plot

半腔热情 提交于 2020-01-04 15:14:29
问题 So I've been searching for an answer for this, and haven't really found anything. I'm hoping there isn't anything like this already on the board so I don't waste anyone's time. In the recent upgrade of I'm assuming RStudio, a method I used to save plots went away. Below is an example chunk of what it looks like: ```{r dummy, dev=c('png', 'pdf'), fig.height=4, fig.width=6} x = 1:10 y = 10:1 plot(x,y) ``` The code will still compile when I do this. However, when I knit my code in order to save

Inline code chunk for non-numeric variables in knitr

核能气质少年 提交于 2020-01-04 06:23:12
问题 I'm trying to use inline R Markdown code to access the first level of a factor. I can get it to work if I use a chunk but not if I do it inline. So while this works: ```{r} as.character(iris$Species[1]) ``` This does not: `r as.character(iris$Species[1])` I could get the inline version to run if I saved the cache and knitted the document twice. I just found this a bit odd because numeric variables behave differently. So, for instance, this works without having to knit it twice `r mean(iris

dev='png' is not working for pdf output in knitr

人盡茶涼 提交于 2020-01-04 04:04:12
问题 In the default setting, knitr will use "'pdf' for LaTeX output and 'png' for HTML/markdown". However, I can specify the dev = "png" in the chunk options for the LaTeX output. This feature is very useful to reduce the file size for big vector figure (e.g. maps). In the previous version of knitr (could be 1.8.*, but not sure), I can specify the dev = "png" (the example below is working for earlier version). Today I installed the latest version of knitr from github (just now). But the dev='png'

dev='png' is not working for pdf output in knitr

不羁的心 提交于 2020-01-04 04:04:05
问题 In the default setting, knitr will use "'pdf' for LaTeX output and 'png' for HTML/markdown". However, I can specify the dev = "png" in the chunk options for the LaTeX output. This feature is very useful to reduce the file size for big vector figure (e.g. maps). In the previous version of knitr (could be 1.8.*, but not sure), I can specify the dev = "png" (the example below is working for earlier version). Today I installed the latest version of knitr from github (just now). But the dev='png'

global comment option for R markdown in knitr

混江龙づ霸主 提交于 2020-01-03 13:59:50
问题 To change the leading characters for the output a knitr chunk in .Rmd has a comment option, like ```{r comment = ""} 1:100 ``` Is there a way to set this globally, not separately for every chunk? opts_knit$set(comment = "") does not work and I cannot find it anywhere in the documentation. 回答1: Use opts_chunk$set() because that is a chunk option; opts_knit is for package options (sorry about the similar names which apparently confused you). See http://yihui.name/knitr/options 来源: https:/