From wdunlap at tibco.com  Fri Jan 14 02:14:05 2011
From: wdunlap at tibco.com (William Dunlap)
Date: Thu, 13 Jan 2011 17:14:05 -0800
Subject: [Rd] why is class externalptr considered recursive?
Message-ID: <77EB52C6DD32BA4D87471DCD70C8D70003CDFEE4@NA-PA-VBE03.na.tibco.com>

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 



[Rd] why is class externalptr considered recursive?
William Dunlap