Body: <p><strong>INITIAL POST:</strong>
  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.</p>
  <pre><code>install.packages(&quot;devtools&quot;)
  devtools::install_github(&quot;maRce10/warbleR&quot;)
  
  #load package
  library(warbleR)
  
  # loading some data from dput to make into a selection table
  example &lt;-structure(list(sound.files = c(&quot;Floodplain_220814_1205.wav&quot;, 
                                           &quot;Floodplain_220814_1205.wav&quot;, &quot;Floodplain_220814_1205.wav&quot;), 
                           selec = 1:3, start = c(4877.33, 4880.5, 4881.5), end = c(4878, 
                                                                                    4881.5, 4882)), row.names = c(NA, 3L), class = &quot;data.frame&quot;)
  
  # building the selection table itself                                                                                                                                  
  exampleselectiontable &lt;- 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:                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
  is_selection_table(exampleselectiontable)
  class(exampleselectiontable)
  
  # install package
  remotes::install_github(&quot;maRce10/ohun&quot;)
  
  #load package
  library(ohun)
  
  # trying to split into 30-second segments:
  split_acoustic_data(sgmt.dur = 30, X = exampleselectiontable)
  </code></pre>
  <p>The error I'm getting says &quot;Error: both objects must be of class 'selection_table'&quot;. 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 &quot;other&quot; selection table might need to be.</p>
  <p>Would appreciate any thoughts.</p>
  <p><strong>EDIT1 Notes added 9/22/2022 in response to comments:</strong>
  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.</p>
  <p>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.</p>
  <p>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.</p>
  <p><strong>EDIT2</strong>: 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:</p>
  <pre><code>data(&quot;lbh1&quot;, &quot;lbh2&quot;)
  writeWave(lbh1, file.path(tempdir(), &quot;lbh1.wav&quot;))
  writeWave(lbh2, file.path(tempdir(), &quot;lbh2.wav&quot;))
  
  #split files in 1 s files
  split_acoustic_data(sgmt.dur = 1, path = tempdir())
  
  # Check this folder
  tempdir()
  </code></pre>
  <p>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.</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-09-21T07:48:53.770Z
Comments.Text: 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?
Comments.UserDisplayName: EcologyTom
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-09-21T13:46:07.000Z
Comments.Text: 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.
Comments.UserDisplayName: ksh530
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-09-21T17:39:16.077Z
Comments.Text: 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.
Comments.UserDisplayName: Taiki Sakai
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-09-21T20:29:55.603Z
Comments.Text: @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?
Comments.UserDisplayName: Cathleen B
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-09-22T21:33:21.417Z
Comments.Text: Thanks for your responses. I added some more detail above in the post.
Comments.UserDisplayName: ksh530
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-09-23T13:05:32.150Z
Comments.Text: @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.
Comments.UserDisplayName: Shannon
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-11-17T10:19:02.920Z
Comments.Text: Please refer to a similar question on the Bioacoustics Stack Exchange, posted here: "[What is an easy way to split .wav files using R or Matlab?](https://bioacoustics.stackexchange.com/questions/235/what-is-an-easy-way-to-split-wav-files-using-r-or-matlab/269#269)"
Comments.UserDisplayName: Chloe
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-05-05T02:11:48.390Z
Comments.Text: I recommend opening an issue on the github [page](https://github.com/ropensci/ohun/issues) if you are having issues with Ohun
Comments.UserDisplayName: Sam Lapp
Tags: <r><ohun>
Title: Error using split_acoustic_data() in R package ohun
ThreadText: # Error using split_acoustic_data() in R package ohun
  
  (Asked by: username_0 on 2022-09-20)
  
  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.
  install.packages("devtools")
  devtools::install_github("maRce10/warbleR")
  
  #load package
  library(warbleR)
  
  # 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:                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
  is_selection_table(exampleselectiontable)
  class(exampleselectiontable)
  
  # install package
  remotes::install_github("maRce10/ohun")
  
  #load package
  library(ohun)
  
  # 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
  tempdir()
  
  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.
  
  **Tags:** r, ohun
  
  > **Comments:**
  > **username_1**: 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?  
  > **username_0**: 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.  
  > **username_2**: 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.  
  > **username_3**: @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?  
  > **username_0**: Thanks for your responses. I added some more detail above in the post.  
  > **username_4**: @username_0- 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.  
  > **username_5**: Please refer to a similar question on the Bioacoustics Stack Exchange, posted here: "[What is an easy way to split .wav files using R or Matlab?](https://bioacoustics.stackexchange.com/questions/235/what-is-an-easy-way-to-split-wav-files-using-r-or-matlab/269#269)"  
  > **username_6**: I recommend opening an issue on the github [page](https://github.com/ropensci/ohun/issues) if you are having issues with Ohun  
  
  ---
  
  ## 0 answers
  
  