HenrikBengtsson / R.oo

R package: R.oo - R Object-Oriented Programming with or without References
https://cran.r-project.org/package=R.oo
20 stars 1 forks source link

getKnownSubclasses() gives an error if one of the objects scanned throws an error #5

Closed HenrikBengtsson closed 9 years ago

HenrikBengtsson commented 9 years ago
> library("hgu133a.db")
> library("R.oo")

> getKnownSubclasses(Object)
Error: hgu133aPFAM is defunct. Please use select() if you need access to PFAM
  or PROSITE accessions.
In addition: Warning messages:
1: In (function ()  :
  hgu133aCHR is deprecated. Please use an appropriate TxDb object or
  package for this kind of data.
2: In (function ()  :
  hgu133aCHRLENGTHS is deprecated. Please use an appropriate TxDb object
  or package for this kind of data.
3: In (function ()  :
  hgu133aCHRLOC is deprecated. Please use an appropriate TxDb object or
  package for this kind of data.
4: In (function ()  :
  hgu133aCHRLOCEND is deprecated. Please use an appropriate TxDb object
  or package for this kind of data.

> traceback()
11: stop(paste(msg, collapse = ""), call. = FALSE, domain = NA)
10: .Defunct(msg = msg)
9: (function ()
   {
       if (grepl("PFAM", x)) {
           bimapName <- paste0(prefix, "PFAM")
       }
       else {
           bimapName <- paste0(prefix, "PROSITE")
       }
       x <- dc[[bimapName]]
       msg = wmsg(paste0(bimapName, " is defunct. ", "Please use select() if you
 need access to PFAM or PROSITE accessions. \n"))
       if (interactive()) {
           .Defunct(msg = msg)
       }
   })()
8: eval(expr, envir, enclos)
7: eval(expr, envir = envir)
6: FUN(c("hgu133a", "hgu133a.db", "hgu133a_dbconn", "hgu133a_dbfile",
   "hgu133a_dbInfo", "hgu133a_dbschema", "hgu133aACCNUM", "hgu133aALIAS2PROBE",

   "hgu133aCHR", "hgu133aCHRLENGTHS", "hgu133aCHRLOC", "hgu133aCHRLOCEND",
   "hgu133aENSEMBL", "hgu133aENSEMBL2PROBE", "hgu133aENTREZID",
   "hgu133aENZYME", "hgu133aENZYME2PROBE", "hgu133aGENENAME", "hgu133aGO",
   "hgu133aGO2ALLPROBES", "hgu133aGO2PROBE", "hgu133aMAP", "hgu133aMAPCOUNTS",
   "hgu133aOMIM", "hgu133aORGANISM", "hgu133aORGPKG", "hgu133aPATH",
   "hgu133aPATH2PROBE", "hgu133aPFAM", "hgu133aPMID", "hgu133aPMID2PROBE",
   "hgu133aPROSITE", "hgu133aREFSEQ", "hgu133aSYMBOL", "hgu133aUNIGENE",
   "hgu133aUNIPROT")[[29L]], ...)
5: lapply(X = X, FUN = FUN, ...)
4: sapply(objectNames, FUN = function(objectName) {
       expr <- substitute({
           is.function(x) && inherits(x, "Class")
       }, list(x = as.name(objectName)))
       eval(expr, envir = envir)
   })
3: getKnownSubclassesInEnvironment(name, envir = envir)
2: getKnownSubclasses.Class(Object)
1: getKnownSubclasses(Object)

The hgu133a.db::hgu133aPFAM object is interesting, because it is an anonymous function that is evaluated when retrieved, e.g.

> hgu133a.db::hgu133aPFAM
Error: hgu133aPFAM is defunct. Please use select() if you need access to PFAM
  or PROSITE accessions.
> str(hgu133a.db::hgu133aPFAM)
Error: hgu133aPFAM is defunct. Please use select() if you need access to PFAM
  or PROSITE accessions.
> body(hgu133a.db::hgu133aPFAM)
Error: hgu133aPFAM is defunct. Please use select() if you need access to PFAM
  or PROSITE accessions.
> is.function(hgu133a.db::hgu133aPFAM)
Error: hgu133aPFAM is defunct. Please use select() if you need access to PFAM
  or PROSITE accessions.
HenrikBengtsson commented 9 years ago

I'm pretty sure the "defunct" error is thrown when getKnownSubclasses() tests whether the object is a function and of class Class or not, i.e.

    # Keep only functions that are Class objects
    keep <- sapply(objectNames, FUN=function(objectName) {
      expr <- substitute({
        is.function(x) && inherits(x, "Class")
      }, list(x=as.name(objectName)));
      eval(expr, envir=envir);
    });

It's possible that this test has to be done using tryCatch() or similar.

HenrikBengtsson commented 9 years ago

For the record, see also R-devel thread 'Inspect a "delayed" assigned whose value throws an error?' started on 2015-01-26.