How to make screw vignette stories using dev.new ()?

My package creates several graphs, often more than once.

When using devices x11or windowsnot, knitrcreates a vignette with the images included.

However, the requirement to submit to the CRAN repository is use dev.newfor a platform-independent build. If I replace x11or windowswith dev.new, then images will not appear in my vignette.

Is there a solution? At first I thought this was due to a plot in RStudio, but using the new argument dev.new(noRStudioGD = FALSE)did not help. In addition, creating a package from the command line did not solve the problem.

Greetings

Tom

(Windows 7 x64) (R 3.1.1) (RStudio 0.98.507)

+4
source share
2 answers

Short answer: you are not using at all dev.new()(or dev.off()or dev.whatever ...). If you want a longer answer, include a minimal reproducible example demonstrating what your problem is.

+2
source

I had the same difficulty. Here is one approach that worked:

p1 <- function(x, knitr=FALSE){
    plot(x)
    if(!knitr) dev.new()
    plot(x^2)
}

The argument is knitr=used only in creating a vignette.

Now in the file .Rnwin /vignettesput something like:

%\VignetteEngine{knitr::knitr}
%\VignetteIndexEntry{p1}
\documentclass{article}

\begin{document}

<<setup, include=FALSE>>=
library("knitr")
### Set global chunk options
opts_chunk$set(eval=TRUE,
   ## text results
   echo=TRUE,
   results=c('markup', 'asis', 'hold', 'hide')[1],
   ## plots
   fig.path=c('figure', 'figure/minimal-')[1],
   fig.keep=c('high', 'none', 'all', 'first', 'last')[1],
   fig.align=c('center', 'left', 'right', 'default')[1],
   fig.show=c('hold', 'asis', 'animate', 'hide')[1],
   dev=c('pdf', 'png', 'tikz')[1],
   fig.width=7, fig.height=7, #inches
   fig.env=c('figure', 'marginfigure')[1],
   fig.pos=c('', 'h', 't', 'b', 'p', 'H')[1]
   )
@

<<plot1>>
library("myPackage")
x <- seq(10)
p1(x, knitr=TRUE)
@

\end{document}
0
source

All Articles