From roebuck at odin.mdacc.tmc.edu  Thu Aug 11 17:03:11 2005
From: roebuck at odin.mdacc.tmc.edu (Paul Roebuck)
Date: Thu, 11 Aug 2005 10:03:11 -0500 (CDT)
Subject: [Rd] Registering S3 class from external package
Message-ID: <Pine.OSF.4.58.0508110835330.193766@odin.mdacc.tmc.edu>

The package I'm working on can extract data from external
packages but would otherwise have no dependency on them.
However, I desire to be able to dispatch based on an
external S3 class if its package is attached (.First.lib).
My code is S4-based and its package has NAMESPACE.

Registering the external class prior to the other
package being attached doesn't seem to work so I am
attempting to perform the registration once the other
package has done so. But my namespace is locked by the
time this occurs. Can someone either tell me how to do
this, suggest a better alternative, or point me to
another package that does something similar?

Current attempt is something like the following:

  setHook(packageEvent("somepkg", "attach"),
          function(...) {
              cat("* Register", sQuote("oldstyle"),
                  "as S3 class", "\n")
              setOldClass(c("oldstyle", "data.frame"),
                          where = asNamespace("mypkg"))
          })


-----------------
> require(mypkg)
Loading required package: mypkg
...
> require(somepkg)
Loading required package: somepkg
* Register 'oldstyle' as S3 class
Error in assign(classMetaName(Class), def, where) :
        cannot add bindings to a locked environment
> R.version.string
[1] "R version 2.1.1, 2005-06-20"

----------------------------------------------------------
SIGSIG -- signature too long (core dumped)



[Rd] Registering S3 class from external package
Paul Roebuck