Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Speed up fig.show interval in knitr

I am creating an html document from an rmarkdown file using knitr and inserting an animation code chunk as follows:

```{r,fig.show='animate'}
for(i in 1:10) plot(rnorm(10))
```

The animation is created just fine, however, I haven't found a way to speed up the animation. For instance, the animation package has the interval argument for saveGIF() which allows one to speed up or slow down a gif. Any suggestions are welcome!

like image 319
Rich Avatar asked Jan 21 '15 22:01

Rich


People also ask

How do I show output in R Markdown?

If you prefer to use the console by default for all your R Markdown documents (restoring the behavior in previous versions of RStudio), you can make Chunk Output in Console the default: Tools -> Options -> R Markdown -> Show output inline for all R Markdown documents .

What is fig retina?

The fig. retina argument is a dpi multiplier for displaying HTML output on retina screens and changes the chunk option dpi to dpi * fig.

How do you use the knitr in RStudio?

If you are using RStudio, then the “Knit” button (Ctrl+Shift+K) will render the document and display a preview of it.

What does eval true do in R?

eval TRUE If FALSE, knitr will not run the code in the code chunk. include TRUE If FALSE, knitr will run the chunk but not include the chunk in the final document. purl TRUE If FALSE, knitr will not include the chunk when running purl() to extract the source code.


1 Answers

The chunk option interval lets you set frame duration, while the aniopts option lets you pass in a string containing options that are passed directly on to the LaTeX package animate. (Both are documented in the "Animation" section of the knitr package's options documentation)

So, for instance, to speed the animation up 5-fold and provide it with controls but no looping, do this:

```{r, fig.show='animate', interval=0.2, aniopts="controls"}
for(i in 1:10) plot(rnorm(10))
```
like image 67
Josh O'Brien Avatar answered Sep 27 '22 15:09

Josh O'Brien