[Rd] Registering S3 class from external package

From: Paul Roebuck <roebuck_at_odin.mdacc.tmc.edu>
Date: Thu 11 Aug 2005 - 15:03:11 GMT

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)

R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Fri Aug 12 01:07:23 2005

This archive was generated by hypermail 2.1.8 : Mon 20 Feb 2006 - 03:21:16 GMT