[R-pkg-devel] use of `dev.new` across platforms in RStudio (Martin Maechler)

Alex Chubaty alex.chubaty at gmail.com
Sun Jun 14 21:46:30 CEST 2015


Thank you Martin for passing this along to RStudio, and thank you JJ for
your reply.

JJ, do you have an estimated timeframe for when this fix will appear?
There's still the issue of RStudio users not updating their software at
each and every release, so it may time some time for `dev.new` to work for
most people.

In the mean time, the best work around I've come up with is as follows. It
checks for RStudio graphics device being set in options and basically
overrides it. The catch is that `setDevice` only works if invoked by the
user in the RStudio console. `unsetDevice` can be put into my package
`.onUnload()`. R CMD check doesn't seem to complain, but I'm not completely
satisfied with this workaround.

setDevice <- function() {
   options(myPackage.device = getOption("device"))  # move this line
to `.onLoad`
   if (getOption("device")=="RStudioGD") {
     if (Sys.info()["sysname"]=="Darwin") {
       options(device="quartz")
     } else if (Sys.info()["sysname"]=="Linux") {
       options(device="x11")
     } else if (Sys.info()["sysname"]=="Windows") {
       options(device="windows") # `dev.new` works on Windows, so
could omit this
     }
   }
  message("Default plot device set to ", getOption("device"), ". ",
          "Remember to reset your default device using `unsetDevice()`.")
}
# unset default graphics device (i.e., return to user's prev setting).
call during `.onUnload`?unsetDevice <- function() {
  if (!is.null(getOption("myPackage.device"))) {
    options(device=getOption("myPackage.device"))
  }
  options(myPackage.device = NULL)
}



Thoughts and suggestions welcome.

Thank you,
Alex

--
amc

On Sun, Jun 14, 2015 at 4:41 AM, JJ Allaire <jj at rstudio.com> wrote:

> > I have neither been involved in the creation of the
> > 'noRStudioGD' option, but from looking at  dev.new() it is clear
> > that it *should* work on all three platforms (Windows, Mac,
> > Linuxen).
> >
> > It is really unfortunate that this still does not work reliably
> > (or stopped working with a new release of "something" ?)...
> >
> > Honestely, I believe it is primarily RStudio's responsibility to
> > ensure that something standard R as  dev.new()  keeps working in
> > their interface to R,= and if it does not, at least contact the R
> > developers (R core) about it.
>
> Currently the RStudio graphics device creation function fails if the
> RStudio device is already active. We will modify this function to
> rather than fail just delegate to the platform-appropriate device
> creation function (which will create an external windows, X11, or
> quartz graphics device window). This will make dev.new work as
> expected within RStudio.
>
> J.J. Allaire
>
> ______________________________________________
> R-package-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-package-devel
>

	[[alternative HTML version deleted]]



More information about the R-package-devel mailing list