2
2
Fork
You've already forked plotenv
0
Evaluate plotting commands in a local environment making it easier to switch output to different devices
  • R 95.1%
  • Makefile 4.9%
2025年07月07日 08:06:12 +02:00
R Added pdf device 2025年07月07日 08:06:12 +02:00
.gitignore Cleanup/organisation 2025年07月07日 07:43:56 +02:00
.Rbuildignore Fix build/check warnings 2025年07月07日 07:59:28 +02:00
DESCRIPTION Basic functioning package 2025年07月06日 17:03:30 +02:00
Makefile Cleanup/organisation 2025年07月07日 07:43:56 +02:00
README.md readme 2025年07月06日 17:33:06 +02:00

plotenv - An R package for making easier to switch between different output devices

Wrap the code for generating a plot into a plotenv:

plotenv("example", {
 par(mar = c(4, 4, 0, 0) + 0.5)
 x <- rnorm(100)
 plot(x, pch = 20)
 grid()
})

The expressions are evaluated in a local environment (as with local()). Therefore, modifications to variables and newly created variables will not affect the global environment. Also plotenv() will ensure the changed to par() and the palette are reset before returning.

Each plotenv has a 'name'. In case of the default plotting device, this is ignored. However, these names are used when we switch the output to other devices. For example, when we change the device to 'png':

plotenv_output("png")

Rerunning the previous plotting commands will result in a file example.png. This makes it really easy to switch between different devices. For example, we could automatically switch at the top of our script between different output devices depending on whether we are running in an interactive session or not:

library(plotenv)
if (interactive()) plotenv_output_default() else plotenv_output("png")

When we have an interactive session, the plots will end up on screen. In a non-interactive session png files are created.

It is also possible to set options for each device. To change the default size of our png files to 1200x800 we can use the following commands:

plotenv_set_options("png", width = 1200, height = 800)

This will apply to all png files generated subsequently. When we want a different resolution for our images we only need to change one line of code.