[R-SIG-Mac] Opening single Terminal window and running syntax sequentially from R

Marc Schwartz marc_schwartz at me.com
Wed Jan 10 18:39:36 CET 2018

> On Jan 10, 2018, at 12:18 PM, Christofer Bogaso <bogaso.christofer at gmail.com> wrote:
> Hi,
> I have an .app file saved in Harddisk, which I want to run from R. So
> below is the code which I use:
> system("open '.../My_File.app'")
> However, if I run above code multiple times (sequentially) then each
> time a new Terminal window opens that make my system cluttered.
> So I wonder if there is any way to use a single Terminal window and
> run above code sequentially there only. R should search if any
> Terminal window is already open and then run syntax on that Terminal
> window only.
> Any pointer will be highly appreciated.
> Thanks,


My initial reaction is that this is outside of R per se and more specific to macOS in terms of how the application is opened at the CLI, runs and then is exited/closed, before the next instance is run.

I would do a Google search on keywords along the lines of "macOS scripting" and/or "macOS open command".

One possibility would be to use the '-W' option for open, which theoretically will force the initial call to wait for the first application instance to be closed/exited before returning.

For example, compare the behaviors of:

  system("open -a TextEdit")


  system("open -W -a TextEdit")

from an R terminal session.

So, depending upon your actual workflow requirements, you may wish to consider using the system() function with a different call, or perhaps create a shell script that can be called via system(), rather than the actual single command, where the shell script can contain a sequence of CLI commands that are relevant to your workflow.


Marc Schwartz

More information about the R-SIG-Mac mailing list