> On Dec 16, 2015, at 7:45 AM, Glenn Schultz <glennmschu...@me.com> wrote:
> 
> Hello All,
> 
> I would like to be able to convert and S4 class to an array but I seem to be 
> stuck.  Reading the documentation I think I need to use setAs() and then as() 
> Below is a minimal example but I cannot get it to work.  So I am doing 
> something wrong but I don't know what it is.
> 
> Any insights/help are appreciated,
> - Glenn
> 
> setClass("AnObject", representation(
> dataone = "numeric",
> datatwo = "numeric"))
> 
> FillObject <- function(){
> one <- rep(10, 20)
> two <- rep(10,20)
> 
> new("AnObject",
> dataone = one,
> datatwo = two)
> }
> 
> MyObject <- FillObject()
> 
> setAs(from = "AnObject" , to = "array", def = function(from) from(AnObject))

Just imitating the example on the ?setAs page I get no error with:

setAs("AnObject" ,"array", def = function(from,to) 
                                        cbind(from@dataone,from@datatwo) )

NewObject <- as(MyObject, "array")


-- 

David Winsemius
Alameda, CA, USA

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to