Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 324
Laura Avatar asked Aug 05 '11 07:08

Laura


3 Answers

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.

like image 85
Hong Ooi Avatar answered Oct 14 '22 08:10

Hong Ooi


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)
like image 20
Marek Avatar answered Oct 14 '22 07:10

Marek


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

like image 5
David Heffernan Avatar answered Oct 14 '22 06:10

David Heffernan