I have a function to search through R code
and look for certain language constructs.
It uses the idiom
    if (is.recursive(object)) {
        object <- as.list(object)
        for(element in object) {
            Recall(element) # recurse further into object
        }
    }
and I was surprised that this fails in as.list
on objects of class "externalptr" because they
are considered recursive but cannot be turned
into lists (nor are they subsettable). 
  > p <- stats:::R_smart[[2]]
  > str(p)
  <externalptr> 
  > class(p)
  [1] "externalptr"
  > is.recursive(p)
  [1] TRUE
  > length(p)
  [1] 1
  > as.list(p)
  Error in as.vector(x, "list") : 
    cannot coerce type 'externalptr' to vector of type 'list'
  > p[[1]]
  Error in p[[1]] : object of type 'externalptr' is not subsettable

I can work around the issue but was wondering what the
rationale for this was.

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com 

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

Reply via email to