1

I have a script that I am using to analyse some audio data in R studio. The script runs with no errors however when I execute it, it simply does nothing. I think it may be an issue with the system2 command. Any help is much appreciated, I am at a loss without even an error message to go by

Here is my code-

# Set the directory containing the files
directory <- "D://Alto//Audio 1//Day 2//"
# The directory to store the results
base_output_directory <- "D://Ecoacoustics//Output//indices_output//"

# Get a list of audio files inside the directory
# (Get-ChildItem is just like ls, or dir)
files <- list.files(directory, pattern = "*.wav", full.names = TRUE)

# iterate through each file
for(file in files) {
 message("Processing ", file) 

  # get just the name of the file
  file_name <- basename(file)

  # make a folder for results
  output_directory <- normalizePath(file.path(base_output_directory, file_name))
  dir.create(output_directory, recursive = TRUE)

  # prepare command
  command <- sprintf('audio2csv "%s" "Towsey.Acoustic.yml" "%s" ', file, output_directory)

  # finally, execute the command
  system2('C://Ecoacoustics//AnalysisPrograms//AnalysisPrograms.exe//', command) 
}
Jenna
  • 111
  • 1
  • You are calling `system` not `system2`. – Rui Barradas Feb 07 '20 at 19:54
  • 1
    Does it ever even say "Processing"? Are you sure there are files in the `files` variable? The `pattern=` in `list.files` should be a regular expression, not a grob style expression. – MrFlick Feb 07 '20 at 19:55
  • And just to be clear, you have a folder named "AnalysisPrograms.exe" that contains a program named "audio2csv"? Or is the program named "AnalysisPrograms.exe" and "audio2csv" is a parameter you want to pass to the function? Also, `args=` should really be a character vector of arguments, not a single string. – MrFlick Feb 07 '20 at 19:58
  • 1
    Check each object by running the script line by line. As already mentioned the regex in `list.files` looks a bit suspicious. Also try to run the body of the loop by 'iterating' manually. Or print the values of the loops variables... – dario Feb 07 '20 at 19:59
  • Perhaps you need `shQuote` {base} – IRTFM Feb 07 '20 at 20:06
  • If I change the line files <- list.files(directory, pattern = "*.wav", full.names = TRUE) to files <- list.files(directory, pattern = "*.WAV", full.names = TRUE), with caps lock on the .WAV it prints 'processing but only empty folders are created, the content is missing. Before when it it was .wav the 'files' was NULL, now it finds the files and creates folders but outputs nothing else. – Jenna Feb 07 '20 at 20:46
  • "AnalysisPrograms.exe" that contains a program named "audio2csv" – Jenna Feb 07 '20 at 20:47
  • Now there is a warning message for each file- In normalizePath(path.expand(path), winslash, mustWork) : path[1]="D://Ecoacoustics//Output//indices_output///20190320_055138.WAV": The system cannot find the file specified – Jenna Feb 07 '20 at 20:54

0 Answers0