10

This is a bit of a strange question, but I thought people here might be interested.

Is it possible to have R cause a file to be opened in another program? For example, could you write a command line that would cause a music file to start playing? The potential application would be that after a model is finished running, music would start to play, alerting you to the model's completion.

Zoe
  • 27,060
  • 21
  • 118
  • 148
Laura
  • 679
  • 2
  • 5
  • 14

3 Answers3

10

In addition to system, on Windows at least you can use shell.exec which will open the file using the application specified in the Windows file associations. For example, shell.exec("file.txt") will open a text file in your favourite text editor, shell.exec("file.mp3") will launch a media player, etc.

Hong Ooi
  • 56,353
  • 13
  • 134
  • 187
7

There is audio package which allow to play wave files:

require(audio)
wave_file <- dir("C:/Windows/Media", pattern="\\.wav$", full.names=TRUE)[1] # some random windows wave file
f <- load.wave(wave_file)
play(f)
Marek
  • 49,472
  • 15
  • 99
  • 121
  • This is pretty cool, but I'm having some trouble opening the .wav files. I get this error message: Error in load.wave(wave_file) : unable to open file 'chimes.wav' – Laura Aug 08 '11 at 00:09
6

You can do this by calling the system() function.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490