INITIAL POST: One of my first times here. I am trying to use a function called split_acoustic_data() in ohun, an R package for processing bioacoustic data. The process involves use of a class of object called a selection table, so I used a subset of a CSV file to build one below. Split_acoustic_data() splits an audio file and its corresponding selection table into smaller pieces, which I am trying to do below with a segment duration of 30 seconds (sgmt.dur = 30). I have read about the function but haven't been able to solve the problem by doing so.


#load package

# loading some data from dput to make into a selection table
example <-structure(list(sound.files = c("Floodplain_220814_1205.wav", 
                                         "Floodplain_220814_1205.wav", "Floodplain_220814_1205.wav"), 
                         selec = 1:3, start = c(4877.33, 4880.5, 4881.5), end = c(4878, 
                                                                                  4881.5, 4882)), row.names = c(NA, 3L), class = "data.frame")

# building the selection table itself                                                                                                                                  
exampleselectiontable <- selection_table(example, max.dur = 2, path = NULL, whole.recs = FALSE,
                                 extended = FALSE, confirm.extended = TRUE, mar = 0.1, by.song = NULL, 
                                 pb = TRUE, parallel = 1, verbose = TRUE)

# double and triple checking to make sure it's a selection table:                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            

# install package

#load package

# trying to split into 30-second segments:
split_acoustic_data(sgmt.dur = 30, X = exampleselectiontable)

The error I'm getting says "Error: both objects must be of class 'selection_table'". What I have there is a selection table, as near as I can tell, and reading the details of split_acoustic_data I haven't found a candidate for what the "other" selection table might need to be.

Would appreciate any thoughts.

EDIT1 Notes added 9/22/2022 in response to comments: Thanks for your thoughts. I believe 30 seconds should work because I think it is splitting the sound file (and might in doing so split the events, but only as a byproduct). However I moved down to 1 second and got the same error.

I also tried running this with materials from the ohun package including lbh1, lbh2, and lbh_reference (the selection table from the ohun package) and got the same error. I could build my own selection table for it next, but I'm starting to think it is something about the way I'm using the split_acoustic_data function, like it is missing another selection table or something.

Someone helped me find this from warbleR: The error comes from warbler::selection_table line 710, (and is the only ref containing both objects and selection_table in warbleR)that is an if test, if (!is_selection_table(X) | !is_selection_table(Y)). I am going to try to learn how to look through the materials better and see if I can figure out what selection table Y might be referring to.

EDIT2: I read about the function online, therefore I missed the example code. The example code is as follows once you've installed the package ohun:

data("lbh1", "lbh2")
writeWave(lbh1, file.path(tempdir(), "lbh1.wav"))
writeWave(lbh2, file.path(tempdir(), "lbh2.wav"))

#split files in 1 s files
split_acoustic_data(sgmt.dur = 1, path = tempdir())

# Check this folder

I still was unable to use X to create a new data frame (same error message as described below), but I used the above to accomplish the splitting. Wanted to post this in case I confused anyone by missing the example code.

  • $\begingroup$ Hi, welcome to BSE. Please add some more details to your question; what does split_acoustic_data do? Have you checked the help file for the expected input for the function? Have you tried contacting the package author about the error? $\endgroup$
    – EcologyTom
    Sep 21, 2022 at 7:48
  • 1
    $\begingroup$ Hi, thanks for your response. Split_acoustic_data() splits sound files and their selection tables (a class of object that is similar to a data frame) into smaller segments. Above, I am trying to split it into segments of 30 seconds each with sgmt.dur = 30. I have read in detail about the function but I have not contacted the package author about the error - was curious to see if others have used this package. $\endgroup$
    – ksh530
    Sep 21, 2022 at 13:46
  • $\begingroup$ What are the units of start, end, and max.dur? I'm not familiar with either package, but it looks like you start off by defining selections that are less than 2 seconds long, and then try to split those into 30-second segments. That might be the source of the error. $\endgroup$ Sep 21, 2022 at 17:39
  • 2
    $\begingroup$ @MarceloAraya-Salas should be able to help! But, your error may be hard for anyone here to reproduce without access to your 'Floodplain_220814_1205.wav' file. Are you able to create a fully reproducible example using the example data that comes with the ohun package, rather than your file? e.g.: # load data and save to temporary working directory data("lbh1", "lbh2") writeWave(lbh1, file.path(tempdir(), "lbh1.wav")) writeWave(lbh2, file.path(tempdir(), "lbh2.wav")) # and then create your example selection table based on one of these files? $\endgroup$
    – Cathleen B
    Sep 21, 2022 at 20:29
  • 1
    $\begingroup$ @ksh530- if you end up finding the answer to your question from different sources other than a direct answer here-- please provide an answer to your own question. This will help others in the future who come across this same problem. $\endgroup$
    – Shannon
    Sep 23, 2022 at 13:05


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.