user2456393
user2456393

Reputation: 3

R - Build batch process // Is this easy?

I'm quite new to programming, but I have a question. I think u can answer this pretty easy.

I have this code

    library(seewave)
    library(tuneR)

    date<-"WAHNHEIDE_20120711_"
    clockings<-scan("testfile.txt", what="")
    date.clock<-paste(date,clockings,sep="")

    wave<-readWave("mywav.wav")
    waveenv<-env(wave, f=48000, envt="hil", plot=FALSE)
    thvalue<-th(waveenv)
    wavespec<-meanspec(wave, f=48000, wl=1024, wn="hanning", plot=FALSE)
    shvalue<-sh(wavespec)
    index<-thvalue*shvalue           
    combine<-c(shvalue, thvalue, index)
    write(combine, file="test.txt", append=TRUE, sep="\t")

I build a string with many filenames (*.wav) I want to analyse. Can I insert all those file names I generated in the "readWave()" part? So that I run the script and it computes the values sh and th for all the files generated in date.clock? Is this easy or hard to code?

Thanks for the help! Cheers Tobi

Okay, I think this is the easiest way to it it since I'm only reading wav files.

    library(seewave)
    library(tuneR)

    files<-list.files(pattern=".wav")

    for (i in 1:length(files)) {
    wave<-readWave(files[i])
    waveenv<-env(wave, f=48000, envt="hil", plot=FALSE)
    thvalue<-th(waveenv)
    wavespec<-meanspec(wave, f=48000, wl=1024, wn="hanning", plot=FALSE)
    shvalue<-sh(wavespec)
    index<-thvalue*shvalue           
    combine<-c(shvalue, thvalue, index)
    write(combine, file="test.txt", append=TRUE, sep="\t")
    }

:)

Upvotes: 0

Views: 180

Answers (1)

exclsr
exclsr

Reputation: 3347

This is relatively easy. One idea is to use a vector to store your file names in a list, and use a for-loop to perform a command for each item in your vector.

Use these references to learn more:

Is that enough information to get you started?

Upvotes: 1

Related Questions