Skip to contents

Open a pdf or screen (GUI) graphic window and return initial graphic parameters.

This order can be used:

width()

open2()

prior_plot() # not for ggplot2

plot() or any other plotting

post_plot() if prior_plot() has been used # not for ggplot2

close2()

Usage

open2(
  pdf = TRUE,
  pdf.path = "working.dir",
  pdf.name = "graph",
  width = 7,
  height = 7,
  paper = "special",
  pdf.overwrite = FALSE,
  rescale = "fixed",
  remove.read.only = TRUE,
  return.output = FALSE,
  safer_check = TRUE
)

Arguments

pdf

Single logical value. Use pdf display? If FALSE, a GUI is opened.

pdf.path

Single character string. Where the pdf is saved (do not terminate by / or \). Write "working.dir" if working directory is required (default). Ignored if pdf == FALSE.

pdf.name

Single character string. Name of the pdf file containing the graphs (the .pdf extension is added by the function, if not detected in the name end). Ignored if pdf == FALSE.

width

Single positive numeric value indicating the width of the window (in inches).

height

Single positive numeric value indicating the height of the window (in inches).

paper

Single character string. Paper argument of the pdf function (paper format). Only used for pdf(). Either "a4", "letter", "legal", "us", "executive", "a4r", "USr" or "special". If "special", means that the paper dimension will be width and height. With another paper format, if width or height is over the size of the paper, width or height will be modified such that the plot is adjusted to the paper dimension (see $dim in the returned list below to see the modified dimensions). Ignored if pdf == FALSE.

pdf.overwrite

Single logical value. Existing pdf can be overwritten? . Ignored if pdf == FALSE.

rescale

Kind of GUI. Either "R", "fit", or "fixed". Ignored on Mac and Linux OS. See ?windows for details.

remove.read.only

Single logical value. Remove the read only (R.O.) graphical parameters? If TRUE, the graphical parameters are returned without the R.O. parameters. The returned $ini.par list can be used to set the par() of a new graphical device. If FALSE, graphical parameters are returned with the R.O. parameters, which provides information like text dimension (see ?par() ). The returned $ini.par list can be used to set the par() of a new graphical device, but generate a warning message. Ignored if return.output == FALSE.

return.output

Single logical value. Return output ? If TRUE the output list is displayed.

safer_check

Single logical value. Perform some "safer" checks (see https://github.com/safer-r)? If TRUE, checkings are performed before main code running: 1) R classical operators (like "<-") not overwritten by another package because of the R scope and 2) required functions and related packages effectively present in local R lybraries. Set to FALSE if this fonction is used inside another "safer" function to avoid pointless multiple checkings.

Value

A list containing:

- $pdf.loc: path of the pdf created.

- $ini.par: initial par() parameters.

- $zone.ini: initial window spliting.

- $dim: dimension of the graphical device (in inches).

Details

WARNINGS

On Linux, use pdf = TRUE, if (GUI) graphic window is not always available, meaning that X is not installed (clusters for instance). Use X11() in R to test if available.

Author

Gael Millot <gael.millot@pasteur.fr>

Yushi Han <yushi.han2000@gmail.com>

Haiding Wang <wanghaiding442@gmail.com>

Examples

if (FALSE) { # \dontrun{
# Screen devices should not be used in examples
open2(pdf = FALSE, pdf.path = ".", pdf.name = "graph", width = 7, height = 7, paper = "special", pdf.overwrite = FALSE, return.output = TRUE)
} # }