Can R cause a file to be opened by another program?
Asked Answered
K

3

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.

Kimberleekimberley answered 5/8, 2011 at 7:14 Comment(7)
You could try if alarm() works for you.Beauharnais
What tune would you play to celebrate your program finishing? The End by The Doors? Probably not joyous enough.Mastitis
I think that this could be appropriate.Reforest
Ride of the Valkyries is always good for the first run of R in the morning. youtube.com/watch?v=ZpvLCptAHT8Cismontane
This is a good question. Sending an email or SMS to a cell phone is very useful when finishing a long job or when awaiting important results.Cismontane
Ha! You guys are the best! I definitely like Ride of the Valkyries. :)Kimberleekimberley
It would be even better if you could play something sad when your program fails.Kimberleekimberley
S
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.

Suspire answered 5/8, 2011 at 7:56 Comment(0)
R
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)
Reforest answered 5/8, 2011 at 8:19 Comment(1)
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'Kimberleekimberley
B
6

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

Brunhild answered 5/8, 2011 at 7:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.