Skip to content

Commit

Permalink
fixes #729: when dev=png, just use png to record plots
Browse files Browse the repository at this point in the history
I should generalize this solution, but I do not have enough time to investigate which devices support plot recording, so just fix this png issue this time
  • Loading branch information
yihui committed Dec 25, 2014
1 parent f89db31 commit bc21f08
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

## MAJOR CHANGES

- when the chunk option `dev = 'png'`, `grDevices::png()` is used to record plots, instead of the default PDF null device (thanks, @yixuan, #729)

- currently R (3.1.2) does not really pass the vignette encoding to vignette engines (which is probably a bug), and **knitr** vignette engines will assume UTF-8 is the file encoding

- when the chunk option `tidy=FALSE`, and `eval` takes a numeric vector, it used to mean the line numbers of the code chunk; now it means the indices of the R expressions in the code chunk, regardless of `tidy=FALSE` or `TRUE` (yihui/knitr-examples#39, thanks, @isomorphisms)
Expand Down
12 changes: 9 additions & 3 deletions R/block.R
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ block_exec = function(options) {
keep = options$fig.keep
# open a device to record plots
if (chunk_device(options$fig.width[1L], options$fig.height[1L], keep != 'none',
options$dev, options$dev.args)) {
options$dev, options$dev.args, options$dpi)) {
# preserve par() settings from the last code chunk
if (keep.pars <- opts_knit$get('global.par'))
par(opts_knit$get('global.pars'))
Expand Down Expand Up @@ -257,9 +257,15 @@ purge_cache = function(options) {

# open a device for a chunk; depending on the option global.device, may or may
# not need to close the device on exit
chunk_device = function(width, height, record = TRUE, dev, dev.args) {
chunk_device = function(width, height, record = TRUE, dev, dev.args, dpi) {
dev_new = function() {
if (identical(getOption('device'), pdf_null)) {
# actually I should adjust the recording device according to dev, but here
# I have only considered the png device
if (identical(dev, 'png')) {
do.call(grDevices::png, c(list(
filename = tempfile(), width = width, height = height, units = 'in', res = dpi
), dev.args))
} else if (identical(getOption('device'), pdf_null)) {
if (!is.null(dev.args)) {
dev.args = get_dargs(dev.args, 'pdf')
dev.args = dev.args[intersect(names(dev.args), c('pointsize', 'bg'))]
Expand Down

0 comments on commit bc21f08

Please sign in to comment.