From maechler at stat.math.ethz.ch  Mon Feb  1 10:26:06 2016
From: maechler at stat.math.ethz.ch (Martin Maechler)
Date: Mon, 1 Feb 2016 10:26:06 +0100
Subject: [Rd] Best way for rgl's .onLoad to fail?
In-Reply-To: <8D38DD51-6E89-410C-AA46-107BB4762B91@depauw.edu>
References: <56AD26EF.5000107@gmail.com>
	<8D38DD51-6E89-410C-AA46-107BB4762B91@depauw.edu>
Message-ID: <22191.9390.120204.712356@stat.math.ethz.ch>

>>>>> "BH" == Bryan Hanson <hanson at depauw.edu>
>>>>>     on Sun, 31 Jan 2016 09:50:46 -0500 writes:

    BH> I think the 2nd option will be more palatable to
    BH> inexperienced users, but both do state the important
    BH> detail.  Bryan

    >> On Jan 30, 2016, at 4:11 PM, Duncan Murdoch <murdoch.duncan at gmail.com> wrote:
    >> 
    >> On OSX and Linux, the rgl package currently requires X11
    >> libs to be available for linking.  Recent versions of OSX
    >> don't include them by default, so I'd like rgl to fail
    >> nicely.
    >> 
    >> Ideally, it will load a library that doesn't need to link
    >> to the X11 libs but will still allow WebGL code to work,
    >> but that's complicated, so I'd like a stopgap.
    >> 
    >> I can detect that the failure is about to happen, and
    >> call stop() in the .onLoad hook, but that gives an ugly
    >> message:
    >> 
    >> > library(rgl)
    >> Error : .onLoad failed in loadNamespace() for 'rgl', details:
    >> call: NULL
    >> error: X11 not found; XQuartz (from www.xquartz.org) is required to run rgl.
    >> Error: package or namespace load failed for ?rgl?

I agree that the error message is a bit messy or even ugly,
however, other than Bryan, I would want  library(.)  to signal
an error when it cannot provide a working package, loaded and
attached to search().

Other functions, such as  require(.)  do rely on this behavior of library(.),
e.g., the much used idiom
  
  if(require(<some package>)) {
      ....
      ....
      ....
  }

needs library() to signal an error on  non-success.

Martin

    >> Alternatively, I can just give a warning and not attempt to load the rgl lib:
    >> 
    >> > library(rgl)
    >> Warning message:
    >> X11 not found; XQuartz (from www.xquartz.org) is required to run rgl.
    >> 
    >> rgl is now loaded, but it doesn't work; just about any function call will give an error, e.g.
    >> 
    >> > plot3d(1,2,3)
    >> Error in rgl.cur() : object 'rgl_dev_getcurrent' not found
    >> 
    >> Do people have opinions about this?
    >> 
    >> One comparable package is RGtk2:  if Gtk2 isn't install, it offers to install it.  I could probably do that for XQuartz.  If the user says no, RGtk2 gives really ugly error messages.  rgl can work without XQuartz, but as I already mentioned, making this work is complicated, so I'd like something simple for now.
    >> 
    >> Duncan Murdoch
    >> 
    >> ______________________________________________
    >> R-devel at r-project.org mailing list
    >> https://stat.ethz.ch/mailman/listinfo/r-devel

    > ______________________________________________
    > R-devel at r-project.org mailing list
    > https://stat.ethz.ch/mailman/listinfo/r-devel



[Rd] Best way for rgl's .onLoad to fail?
Martin Maechler