Error in seq ...: wrong sign in "by" argument

Hi.
I'm using the package "seewave" to extract some features from audiofiles. One of the functions, "timer" on the backstage kind of create a plot and find, according to the parameters, where the sounds and the silences of the audio waves are. I'm trying to get how many sounds and silences are on all my files with a loop.

However, it is stopping on the 20% and I got the following:

Error in seq.default(1, n - msmooth[1], msmooth[1] - (msmooth[2] * msmooth[1]/100)) : wrong sign in 'by' argument

My code goes like so:

path <- 'directory'
audio_files <- dir(path, pattern='wav$')

sound_trials <- vector(mode = "list", length = length(audio_files)) #vector to store audio files
len_timer_trials <- vector(mode = "numeric", length = length(audio_files)) #vector to store number of sounds
pb <- txtProgressBar(min=1, max=length(audio_files), style=3) #progress bar
for (i in 1:length(audio_files))
{
  tmp <- readWave(paste('path', audio_files[i], sep='/')) #read audio files 
  sound_trials[[i]] <- timer(tmp, 44100, envt = 'abs', threshold = 15, msmoot = c(500,10)) #probably my parameters don't fit with all my files, having as a result that error?
  len_timer_trials[i] <- length(sound_trials[[i]]$s) #bring me how many sounds are detected for each file
  setTxtProgressBar(pb, i) #progress bar
}
close(pb) #progress bar
rm(pb) #remove progress bar

According to the documentation there is no "by" argument to set, so I'm not understanding this error. I think it might be that the number, but certainly i don't know. Some human help, please?
If it is something that is happening with a specific file, is it possible to add some sort of break to continue to my next file? All help is highly appreciated!

I don't know which line of your code generates this error (I also don't understand what are n and msmooth), but I just wanted to point out that seq indeed has a by argument:

seq(from = 1, to = 1, by = ((to - from)/(length.out - 1)),
length.out = NULL, along.with = NULL, ...)

Also, note these:

seq(10, 100, 10)
#>  [1]  10  20  30  40  50  60  70  80  90 100
seq(10, 100, -10)
#> Error in seq.default(10, 100, -10): wrong sign in 'by' argument
seq(100, 10, -10)
#>  [1] 100  90  80  70  60  50  40  30  20  10
seq(100, 10, 10)
#> Error in seq.default(100, 10, 10): wrong sign in 'by' argument

Having this information, you may figure out the problem yourself.

In case you don't, please provide a REPRoducible EXample of your problem. It provides more specifics of your problem, and it helps others to understand what problem you are facing.

In case you don't know how to make a reprex, here's a great link:

2 Likes

Hi Yarnabrina.
Thank you for your reply.
I added a function to skip the cases that don't fit to the parameters set for the smoothing (msmooth is a function to do so). The errors were due to the cases in which it was not possible to apply the function (audios too short or without sounds).
To skip those, I follow the recommentadion from Skipping error from for loop

I will take into account your recommendation about providing REPRoducible EXamples for further ocassions. Thanks :slight_smile:

Done. Thanks for the following up. Have a nice day :slight_smile:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.