r - 从列表向量monitoR中提取S4对象
问题描述
我有一个列表向量,其中包含来自该monitoR::makeCorTemplate
函数的 S4 相关模板。
temps_0 <- vector(mode = 'list',length=length(tru_files_info_0$species_id))
for (j in 1: length(tru_files_info_0$species_id)) {
temps_0[j] <- MonitoR::makeCorTemplate(paste0('tru_tp_files','/',paste0(tru_files_info_0$recording_id[j],'',
'.wav')), t.lim =c(tru_files_info_0$t_min[j], tru_files_info_0$t_max[j]),
frq.lim = c(tru_files_info_0$f_min[j]/1000, tru_files_info_0$f_max[j]/1000),
select = 'auto', dens =1, score.cutoff = 0.2, name = tru_files_info_0$new_name[j])
+ }```
Resulting object
Formal class 'corTemplateList' [package "monitoR"] with 1 slot
..@ templates:List of 1
.. ..$ 00d442df7_0:Formal class 'corTemplate' [package "monitoR"] with 15 slots
.. .. .. ..@ clip.path : chr "tru_tp_files/00d442df7.wav"
.. .. .. ..@ samp.rate : int 48000
.. .. .. ..@ pts : num [1:1924, 1:3] 1 1 1 1 1 1 1 1 1 1 ...
.. .. .. .. ..- attr(*, "dimnames")=List of 2
.. .. .. .. .. ..$ : NULL
.. .. .. .. .. ..$ : chr [1:3] "t" "frq" "amp"
.. .. .. ..@ t.step : num 0.0107
.. .. .. ..@ frq.step : num 0.0938
.. .. .. ..@ n.t.bins : int 73
.. .. .. ..@ first.t.bin : num 19.4
.. .. .. ..@ n.frq.bins : int 25
.. .. .. ..@ duration : num 0.779
.. .. .. ..@ frq.lim : num [1:2] 5.91 8.25
.. .. .. ..@ wl : int 512
.. .. .. ..@ ovlp : int 0
.. .. .. ..@ wn : chr "hanning"
.. .. .. ..@ score.cutoff: num 0.2
.. .. .. ..@ comment : chr ""
下一个处理步骤是通过 combineCorTemplates 组合这 10 个模板:
> ctemps_0 <- monitoR::combineCorTemplates(temps_0[[1]], temps_0[[2]], temps_0[[3]], temps_0[[4]], temps_0[[5]], temps_0[[6]], temps_0[[7]], temps_0[[8]], temps_0[[9]], temps_0[[10]])
> ctemps_0
Object of class "corTemplateList"
containing 10 templates
original.recording sample.rate lower.frequency
00d442df7_0 tru_tp_files/00d442df7.wav 48000 5.906
0ea8ea68a_0 tru_tp_files/0ea8ea68a.wav 48000 5.906
2e40b2294_0 tru_tp_files/2e40b2294.wav 48000 5.906
45c356538_0 tru_tp_files/45c356538.wav 48000 5.906
我的问题是,如何在不写出每个列表元素的情况下从列表向量中提取 S4,combineCorTemplates(temps_0[[1]], temps_0[[2]], & etc
因为这很容易出错。
解决方案
我们可以使用do.call
c_temps_0 <- do.call(monitoR::combineCorTemplates, temps_0)
-测试
c_temps_1 <- combineCorTemplates(temps_0[[1]], temps_0[[2]],
temps_0[[3]], temps_0[[4]])
identical(c_temps_0, c_temps_1)
#[1] TRUE
注意:可重现的示例是从?combineCorTemplates
推荐阅读
- android - OnItemClickListener() 用于列表视图的每个项目中的微调器
- java - 如何使用 Java 模仿 PHP 匿名类?
- java - C# 转换中的 HttpURLConnection REST API
- python - 如何以更快的方式从数据框中删除一系列行
- python - 遵循 Odoo 教程 - 无处可去 - 似乎很正常
- php - 在 AWS 上运行 PHP 和 R
- reactjs - 在提交时使用成功或错误消息反应更新表单
- java - 从 ByteBuffer 中获取位
- java - 忽略拆分 \\w+ 上的点
- reactjs - Hooks:如何获取全局状态(this.state)?