4

First question here, hope I did asking part right.

I'm trying to write a short piece of R code that will create a vector with lenghts of all of audiofiles in my 'Music' folder. I'm using RStudio 0.98.501 with R 3.0.3 on i686-pc-linux-gnu (32-bit). I use tuneR package to extract info about lengths of the songs. Here's a problem: I export first MP3 file fine, but when I do it to the second MP3, it gives me 'R Session aborted, R encountered a fatal error, the session will be terminated'.

I'm working on Intel® Atom™ CPU N2800 @ 1.86GHz × 4 with 2 Gb memory with Ubuntu 13.10.

I put my code below, just change the directory for the one where your Music folder is.

    library(tuneR)
    # Set your working directory here
    ddpath <-  "/home/daniel/"
    wdpath  <- ddpath
    setwd(wdpath)
    # Create a character vector with all filenames
    filenames <- list.files("Music", pattern="*.mp3",
                            full.names=TRUE, recursive=TRUE)
    # How many audio files do we have?
    numTracks <- length(filenames)
    # Vector to store lengths
    lengthVector <- numeric(0)

    # Here problem arises
    for (i in 1:numTracks){
      numWave <- readMP3(filenames[i])
      lengthSec <- length(numWave@left)/numWave@samp.rate
      lengthVector <- c(lengthVector, lengthSec)
      rm(numWave)
    }
Michele
  • 8,563
  • 6
  • 45
  • 72
  • 2
    First: try this from the R-gui (or command line) so you can rule out RStudio as the culprit. Next, make sure it isn't always crashing on the **same** `mp3` file. Side notes: no need for `rm(numWave)` as the next assignment will overwrite; and it's good practice to preallocate `lengthVector<-rep(0,numTracks)` rather than concatenating every time thru the loop. – Carl Witthoft Mar 25 '14 at 13:12
  • 1
    @CarlWitthoft,thanks for response! Yes, error is still there in R Commander or in command line, and yes, this works with every MP3 file: any first one goes, any second one causes crash. – Daniel Shestakov Mar 25 '14 at 17:48
  • 1
    I cannot reproduce this problem: R3.0.3, OSX, mp3 files from iTunes library subdirectory with 11 files. Your loop runs flawlessly and produces 11 values. – Carl Witthoft Mar 26 '14 at 00:21
  • @CarlWitthoft Thanks! I suppose it is something about my memory constraints. – Daniel Shestakov Mar 26 '14 at 08:27

0 Answers0