开发者

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

开发者 https://www.devze.com 2023-03-26 06:09 出处:网络
This is a bit 开发者_如何学JAVAof a strange question, but I thought people here might be interested.

This is a bit 开发者_如何学JAVAof 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.


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.


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)


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

0

精彩评论

暂无评论...
验证码 换一张
取 消