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?
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.
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.
By using invisible() function we can suppress the output.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With