[Rd] why is class externalptr considered recursive?
William Dunlap
wdunlap at tibco.com
Fri Jan 14 02:14:05 CET 2011
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
More information about the R-devel
mailing list