【发布时间】: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 这是一个有趣的问题,似乎没有重复。也许您可以将您的评论变成您自己问题的答案。如果你愿意,我会支持它。