hello

we are developing an R package called ANTsR for which we have some special
types.

one of these types is an " antsMatrix " type.

we implemented a "as.data.frame" function that casts an antsMatrix to a
data.frame

this works fine in a basic shell script.   for instance:

# install
R CMD INSTALL ANTsR
# open
R
# in R do
library(ANTsR)
a <- new( "antsMatrix", "float" )
b <- as.data.frame( a )

this all works fine and i am pleased.

fyi, the implementation of as.data.frame is:

setMethod( f = "as.data.frame" ,
   signature( x = "antsMatrix" ) ,
   definition = function( x )
          {
  lst = .Call( "antsMatrix_asList" , x )
 names(lst)[ 1 : (length(lst)) ] <- lst[[ length(lst) ]]
lst[[ length(lst) ]] <- NULL
                        as.data.frame(lst)
}
   )


now the problem comes when i try to access the same functionality in a
function that is within my package R source.

i.e. the function is defined in   ANTsR/R/test.R   which reads

test <- function(...)
{
  a <- new( "antsMatrix", "float" )
  b <- as.data.frame( a )
}

this should produce the same behavior as above, i would think.

but somehow , i get different behavior:

library(ANTsR)
test()

produces :

Error in as.data.frame.default(a) :
  cannot coerce class 'structure("antsMatrix", package = "ANTsR")' into a
data.frame

it is clear to me what's happening ----- R is trying to use the default
implementation of as.data.frame

which clearly won't work on an antsMatrix type.

the issue is --- i do not know why R is not using the correct type-specific
implementation when

this function is called as opposed to when the same operations are called
within the shell.

certainly there must be some simple error on our part in implementation but
i cannot find

what it is --- i am the 3rd person who has looked into this.   it's true
that we are all novice R

developers .... am hoping someone on the list can provide some insight.

many thanks for your time,

brian

	[[alternative HTML version deleted]]

