> On Dec 16, 2015, at 7:45 AM, Glenn Schultz <glennmschultz at 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 at dataone,from at datatwo) )
NewObject <- as(MyObject, "array")
--
David Winsemius
Alameda, CA, USA