Henrik Bengtsson
2011-Nov-05 22:08 UTC
[Rd] How to infer default width and height for a device?
Hi. GENERAL: Is there a general method for inferring default device settings, particularly 'width' and 'height', that works for all devices? AFAIK, the answer is no, but there might be functions out there that I don't know of. POSTSCRIPT SPECIFIC: If not, I'm considering implementing such a method myself. Is it possible for R to infer the default 'width' and 'height' for the *postscript* device, or is this defined outside of R? I've noticed that they are not defined by the arguments to postcript():> args(grDevices::postscript)function (file = ifelse(onefile, "Rplots.ps", "Rplot%03d.ps"), onefile, family, title, fonts, encoding, bg, fg, width, height, horizontal, pointsize, paper, pagecentre, print.it, command, colormodel, useKerning, fillOddEven) and in the list of predefined device options they are zero:> ps.options()[c("width", "height")]$width [1] 0 $height [1] 0 and debugging postcript() they are indeed passed as zeros to .External(PostScript, ...).> sessionInfo()R version 2.14.0 Patched (2011-11-03 r57560) Platform: x86_64-pc-mingw32/x64 (64-bit) locale: [1] LC_COLLATE=English_United States.1252 [2] LC_CTYPE=English_United States.1252 [3] LC_MONETARY=English_United States.1252 [4] LC_NUMERIC=C [5] LC_TIME=English_United States.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] R.utils_1.9.0 R.oo_1.8.3 R.methodsS3_1.2.1 loaded via a namespace (and not attached): [1] tools_2.14.0 Thanks Henrik
Henrik Bengtsson
2011-Nov-05 22:35 UTC
[Rd] How to infer default width and height for a device?
On Sat, Nov 5, 2011 at 3:08 PM, Henrik Bengtsson <hb at biostat.ucsf.edu> wrote:> Hi. > > GENERAL: > Is there a general method for inferring default device settings, > particularly 'width' and 'height', that works for all devices? ?AFAIK, > the answer is no, but there might be functions out there that I don't > know of. > > > POSTSCRIPT SPECIFIC: > If not, I'm considering implementing such a method myself. ?Is it > possible for R to infer the default 'width' and 'height' for the > *postscript* device, or is this defined outside of R? ?I've noticed > that they are not defined by the arguments to postcript(): > >> args(grDevices::postscript) > function (file = ifelse(onefile, "Rplots.ps", "Rplot%03d.ps"), > ? ?onefile, family, title, fonts, encoding, bg, fg, width, height, > ? ?horizontal, pointsize, paper, pagecentre, print.it, command, > ? ?colormodel, useKerning, fillOddEven) > > and in the list of predefined device options they are zero: > >> ps.options()[c("width", "height")] > $width > [1] 0 > $height > [1] 0 > > and debugging postcript() they are indeed passed as zeros to > .External(PostScript, ...).I've already got one reply offline (thanks) pointing me to help("postcript") and its argument 'paper': <quote>the size of paper in the printer. The choices are "a4", "letter" (or "us"), "legal" and "executive" (and these can be capitalized). Also, "special" can be used, when arguments width and height specify the paper size. A further choice is "default" (the default): If this is selected, the papersize is taken from the option "papersize" if that is set and to "a4" if it is unset or empty.</quote> which in code becomes: getPSDimensions <- function(options=ps.options(), ...) { knownDimensions <- list( executive=c(7.25,10.5), legal=c(8.5,14), letter=c(8.5,11), a4=c(8.27, 11.69) ); # See argument 'paper' in help("postcript"). paper <- tolower(options$paper); if (paper == "default") { paper <- getOption("papersize", "a4"); } knownDimensions[[paper]]; } # getPSDimensions() /Henrik> > >> sessionInfo() > R version 2.14.0 Patched (2011-11-03 r57560) > Platform: x86_64-pc-mingw32/x64 (64-bit) > > locale: > [1] LC_COLLATE=English_United States.1252 > [2] LC_CTYPE=English_United States.1252 > [3] LC_MONETARY=English_United States.1252 > [4] LC_NUMERIC=C > [5] LC_TIME=English_United States.1252 > > attached base packages: > [1] stats ? ? graphics ?grDevices utils ? ? datasets ?methods ? base > > other attached packages: > [1] R.utils_1.9.0 ? ? R.oo_1.8.3 ? ? ? ?R.methodsS3_1.2.1 > > loaded via a namespace (and not attached): > [1] tools_2.14.0 > > Thanks > > Henrik >