Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide figures in knitr, but create them as png?

Tags:

r

figure

knitr

I am currently doing some statistical analysis in R and use knitr to generate results and an overview document.

There are some additional plots, which I want to be done and saved as a .png (with specified file name and location), but not included in the generated .html file (too many of them, and they are not at the end).

Using dev.copy(png, ...) works fine for generating the plots, but the figures appear in the .html. If I specify fig.keep=none the .png files are created, but blank.

Is there some way to do what I want?

like image 925
Tim Avatar asked May 11 '15 09:05

Tim


People also ask

How do I hide plots in RMarkdown?

You use results="hide" to hide the results/output (but here the code would still be displayed). You use include=FALSE to have the chunk evaluated, but neither the code nor its output displayed.

How do I hide code but show output in R markdown?

include = FALSE prevents code and results from appearing in the finished file. R Markdown still runs the code in the chunk, and the results can be used by other chunks. echo = FALSE prevents code, but not the results from appearing in the finished file. This is a useful way to embed figures.

How do I suppress the output code in R?

By using invisible() function we can suppress the output.

How do you prevent a code block from being executed when you knit the document?

If you don't want any code chunks to run you can add eval = FALSE in your setup chunk with knitr::opts_chunk$set() . If you want only some chunks to run you can add eval = FALSE to only the chunk headers of those you don't want to run.


1 Answers

This is from knitr website:

fig.show: ('asis'; character) how to show/arrange the plots; four possible values are

  • asis: show plots exactly in places where they were generated (as if the code were run in an R terminal)

  • hold: hold all plots and output them in the very end of a code chunk

  • animate: wrap all plots into an animation if there are mutiple plots in a chunk

  • hide: generate plot files but hide them in the output document

fig.show = 'hide' worked for me.

like image 71
Roman Luštrik Avatar answered Oct 26 '22 05:10

Roman Luštrik