【问题标题】:Extract S4 object from list vector monitoR从列表向量monitoR中提取S4对象
【发布时间】:2021-04-09 02:25:41
【问题描述】:

我有一个列表向量,其中包含来自 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]], &amp; etc 因为这很容易出错。

【问题讨论】:

    标签: r list extract s4 acoustics


    【解决方案1】:

    我们可以使用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 创建的

    【讨论】:

      猜你喜欢
      • 2021-09-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-22
      • 1970-01-01
      相关资源
      最近更新 更多