[R] cloning a graphics window
Kenneth Knoblauch
ken@knob|@uch @end|ng |rom |n@erm@|r
Wed Jul 31 14:45:06 CEST 2024
I often want to get a graphics window that is the same size as one that I resized by hand
(because it was quicker than setting the width and height directly in dev.new)
and have sometimes resorted to using a ruler on my screen or just resize matching.
I came up with the following function that does what I want
dev.clone <- function(){
if(is.null(dev.list())) stop("No active graphics window!")
dev.size() |>
as.list() |>
setNames(c("width", 'height')) |>
do.call(dev.new, args = _ )
invisible(dev.size())
}
I thought that I might be able to leverage the new %||% operator but
wasn't able to get the logic to work out as I wanted.
I haven't found another function to do this. dev.copy doesn't keep
the dimensions of the previous plot, but maybe there is a more
concise and direct way to achieve this that has escaped me.
If anyone knows?
Thanks.
best,
Ken
R version 4.4.1 Patched (2024-06-15 r86749)
Platform: x86_64-apple-darwin20
Running under: macOS Monterey 12.7.6
Matrix products: default
BLAS: /Library/Frameworks/R.framework/Versions/4.4-x86_64/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.4-x86_64/Resources/lib/libRlapack.dylib; LAPACK version 3.12.0
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
time zone: Europe/Paris
tzcode source: internal
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] compiler_4.4.1 tools_4.4.1
___
Kenneth Knoblauch
Inserm U1208
Stem-cell and Brain Research Institute
18 avenue du Doyen Lépine
69500 Bron
France
tel: +33 (0)4 72 91 34 77
fax: +33 (0)4 72 91 34 61
portable: +33 (0)6 84 10 64 10
https://sbri.fr/public-profile/63/single-member/
More information about the R-help
mailing list