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

MacQueen, Don macqueen1 at llnl.gov
Thu Jan 11 18:18:41 CET 2018


I would tend to agree that this is outside of R, unless the My_File.app is intended to run an R script.

However, Terminal has a Preference setting that specifies whether its windows close when the shell exits. I believe the default is to not close. Try changing it.

-Don

--
Don MacQueen
Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062
Lab cell 925-724-7509
 
 

On 1/10/18, 9:39 AM, "R-SIG-Mac on behalf of Marc Schwartz" <r-sig-mac-bounces at r-project.org on behalf of marc_schwartz at me.com> wrote:

    > 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,
    
    
    Hi,
    
    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")
    
    versus:
    
      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.
    
    Regards,
    
    Marc Schwartz
    
    _______________________________________________
    R-SIG-Mac mailing list
    R-SIG-Mac at r-project.org
    https://stat.ethz.ch/mailman/listinfo/r-sig-mac
    



More information about the R-SIG-Mac mailing list