【问题标题】:vapply fun.value S4vapply fun.value S4
【发布时间】:2018-05-27 08:31:06
【问题描述】:

我很难找到我的 vapply 的 FUN.VALUE:

> 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 吗?

谢谢

【问题讨论】:

  • 您可以将vapply 与非原始类型一起使用,但结果将是一个列表。你不妨改用lapply,因为无论如何你都会得到一个列表。
  • 这对我有用:unlist(vapply(ind, function(x) list(dataset[[x]]), c(new("PlotSetPair")))。非常感谢@johnColeman @JDL
  • @nicoluca 这是一个有趣的问题,似乎没有重复。也许您可以将您的评论变成您自己问题的答案。如果你愿意,我会支持它。

标签: r apply s4


【解决方案1】:

这对我有用:

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

诀窍是使用c() 使其成为一个列表,从而将dataset[[x]] 强制转换为list(dataset[[x]]。那我就不列了。

非常感谢@johnColeman @JDL

【讨论】:

    猜你喜欢
    • 2019-01-10
    • 1970-01-01
    • 2017-08-06
    • 2022-10-08
    • 1970-01-01
    • 2017-09-16
    • 2020-01-22
    • 1970-01-01
    • 2012-09-02
    相关资源
    最近更新 更多