vapply fun.value S4

时间:2017-12-13 12:37:29

标签: r apply s4

我很难找到什么应该是我的FUN.VALUE我的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"   

我尝试了以下可能性但没有成功:

> 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

是否有解决方案或我是否只能使用原始类型的vapply?

由于

1 个答案:

答案 0 :(得分:2)

这对我有用:

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

诀窍是使用c()将其设为列表,然后将dataset[[x]]强制转换为list(dataset[[x]]。然后我取消它。

非常感谢@johnColeman @JDL