From xie at yihui.name  Fri Oct 25 18:23:36 2013
From: xie at yihui.name (Yihui Xie)
Date: Fri, 25 Oct 2013 11:23:36 -0500
Subject: [Rd] appropriate work-around for problems with a specific plot
 device (Rstudio)?
In-Reply-To: <CALxY2Lf4SORY6a_t2sOmcs57cMat3qavVnGM+0coZWG2i8Nx1g@mail.gmail.com>
References: <5269B791.1040808@skyeome.net> <1382692784.7000.35.camel@milan>
	<CALxY2Lf4SORY6a_t2sOmcs57cMat3qavVnGM+0coZWG2i8Nx1g@mail.gmail.com>
Message-ID: <CANROs4dwUeDh6LMB=m0icfKTQrdj2F=77YXBpzpJEgpu61VJ7g@mail.gmail.com>

You can see how R sets up the device option in grDevices:::.onLoad,
but unfortunately the code there is not easily usable.

I think you can treat the NOTE in R CMD check as a false warning and
explain the situation to CRAN maintainers in the email. Code analysis
using codetools in R CMD check is not always reliable. I'm not sure if
grDevices::quartz, grDevices::x11, and grDevices::windows can "fix"
the NOTE.

Regards,
Yihui
--
Yihui Xie <xieyihui at gmail.com>
Web: http://yihui.name
Department of Statistics, Iowa State University
2215 Snedecor Hall, Ames, IA


On Fri, Oct 25, 2013 at 9:24 AM, Lorenz, David <lorenz at usgs.gov> wrote:
> Skye,
>   I ran into a similar problem with RStudio. My solution was just to check
> if "windows" exists and if it does, open windows, then check "quartz" and
> so forth. You can restrict the exists function to look only in grDevices.
> Dave
>
>
> On Fri, Oct 25, 2013 at 4:19 AM, Milan Bouchet-Valat <nalimilan at club.fr>wrote:
>
>> Le jeudi 24 octobre 2013 ? 17:13 -0700, Skye Bender-deMoll a ?crit :
>> > Dear r-devel-opers,
>> >
>> > I'm working on a package that does some plot-intensive work using the
>> > animation library.  It turns out that this performs very badly in the
>> > RStudio plot device, which is the preferred IDE for our team.  Our
>> > kludgy solution is to detect if the Rstudio device is running, and if
>> > so, open another plot device to do the rendering and close it when done:
>> >
>> > externalDevice<-FALSE
>> >    if (!is.function(options()$device)){
>> >      if (names(dev.cur())=="RStudioGD"){
>> >        message("RStudio's graphics device is not well supported by ndtv,
>> > attempting to open another type of plot window")
>> >        # try to open a new platform-appropriate plot window
>> >        if (.Platform$OS.type=='windows'){
>> >          windows()
>> >        } else if(length(grep(R.version$platform,pattern='apple'))>0)  #
>> > is it mac?
>> >        {
>> >          quartz()
>> >        } else {  # must be unix
>> >          x11()
>> >        }
>> >        externalDevice<-TRUE
>> >      }
>> >    }
>> >
>> > [render a whole bunch of plot frames]
>> >
>> > # turn off external device if using one
>> >    if (externalDevice){
>> >      dev.off()
>> >    }
>> >
>> > Although this works well for us in practice, when testing against R
>> > devel, we get the following NOTE:
>> >
>> >
>> > * checking R code for possible problems ... NOTE
>> > Found an obsolete/platform-specific call in the following function:
>> >    ?render.animation?
>> > Found the platform-specific devices:
>> >    ?quartz? ?windows? ?x11?
>> > dev.new() is the preferred way to open a new device, in the unlikely
>> > event one is needed.
>> >
>> >
>> > Is there a better way to resolve this situation?  We can't use dev.new()
>> > to open the plot device, because RStudio has set the value of
>> > getOption("device") to "RStudioGD".  Can anyone recommend an alternative
>> > method of generating a platform-appropriate device to open that won't
>> > generate R CMD check issues?
>> How about temporarily changing the value of the "device" option to what
>> you need?
>>
>> I think you should also get in touch with RStudio developers to see
>> whether something can be done about the poor performance.
>>
>>
>> My two cents



[Rd] appropriate work-around for problems with a specific plot device (Rstudio)?
Yihui Xie