- R 95.1%
- Makefile 4.9%
| R | Added pdf device | |
| .gitignore | Cleanup/organisation | |
| .Rbuildignore | Fix build/check warnings | |
| DESCRIPTION | Basic functioning package | |
| Makefile | Cleanup/organisation | |
| README.md | readme | |
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.