Search code examples
rapplyr-s4

vapply fun.value S4


I am having a hard time finding what should be my FUN.VALUE of my vapply:

> sapply(ind, function(x) typeof(dataset[[x]]))
[1] "S4"
> sapply(ind, function(x) mode(dataset[[x]]))
[1] "S4"
> sapply(ind, function(x) storage.mode(dataset[[x]]))
[1] "S4"
> sapply(ind, function(x) is(dataset[[x]]))
 [,1]          
 [1,] "PlotSetPair" 
 [2,] "envRefClass" 
 [3,] ".environment"
 [4,] "refClass"    
 [5,] "environment" 
 [6,] "refObject"   
 [7,] "AssayData"   

I have tried the following possibilities without success:

> vapply(ind, function(x){return(dataset[[x]]);}, S4)
Error in vapply(ind, function(x) { : object 'S4' not found
> vapply(ind, function(x){return(dataset[[x]]);}, "S4")
Error in vapply(ind, function(x) { : values must be type 'character',
 but FUN(X[[1]]) result is type 'S4'
> vapply(ind, function(x){return(dataset[[x]]);}, "S4-class")
Error in vapply(ind, function(x) { : values must be type 'character',
but FUN(X[[1]]) result is type 'S4'
> vapply(ind, function(x){return(dataset[[x]]);}, S4-class)
Error in vapply(ind, function(x) { : object 'S4' not found
> vapply(ind, function(x){return(dataset[[x]]);}, PlotSetPair)
Error in vapply(ind, function(x) { : object 'PlotSetPair' not found
> vapply(ind, function(x){return(dataset[[x]]);}, PlotSetPair())
Error in PlotSetPair() : could not find function "PlotSetPair"
> vapply(ind, function(x){return(dataset[[x]]);}, seqplots::PlotSetPair())
Error: 'PlotSetPair' is not an exported object from 'namespace:seqplots'
> vapply(ind, function(x){return(dataset[[x]]);}, seqplots::PlotSetPair)
Error: 'PlotSetPair' is not an exported object from 'namespace:seqplots'
> vapply(ind, function(x){return(dataset[[x]]);}, PlotSetPair-class)
Error in vapply(ind, function(x) { : object 'PlotSetPair' not found

Is there a solution or can I use only vapply with primitive types?

Thanks


Solution

  • This worked for me:

    unlist(vapply(ind, function(x) list(dataset[[x]]), c(new("PlotSetPair")))

    The trick was to use c() to make it a list and therefore coerce dataset[[x]] to list(dataset[[x]]. I unlist it then.

    Thanks a lot @johnColeman @JDL