[R-pkg-devel] A bug in rgl caused S3 methods to fail to register

Duncan Murdoch murdoch@dunc@n @ending from gm@il@com
Fri Sep 21 15:26:58 CEST 2018


I've just spent a couple of days tracking down a bug in rgl.  The 
symptoms were that when the X11 display was unavailable, S3 methods from 
a package that used rgl failed to show up.

Specifically,

library(nat)
methods("plot3d")

would only show the rgl methods, not the ones that nat added.

The cause was a bug in rgl.  When the X11 initialization fails, rgl 
tries to restart itself with the "NULL" driver.  (This maintains 
structures in memory, but doesn't display anything:  useful for working 
with WebGL, or for testing.)  As part of that restart, I had a line calling

   unloadNamespace("rgl")

R was nice enough to reload the namespace when it was needed next, but
this caused internal inconsistencies in the S3 methods functions, 
because some of them still accessed the old copy of the namespace, and 
some of them accessed the new one.  (They both printed as

<environment: namespace:rgl>

but identical(ns1, ns2) could tell that they were not the same.)

Hopefully if anyone else is ever dumb enough to unload their own 
namespace, this message will help them to fix the bug.

Duncan Murdoch



More information about the R-package-devel mailing list