There have recently been some problems while running packages using Tcl/Tk with
R.app GUI under Mac Os X Mavericks (10.9). It is also well known that it is not
a good idea to work with R.app and a custom builded R that uses the Aqua
version of Tcl/Tk.
Simple solution for these problems is to use command line R (i.e. R in terminal
window) instead of R.app GUI. Although it is not particularly difficult to
launch terminal application and then R from the prompt, it would be nice to
have an icon on the dock to launch the command line R with one click.
After some experiencing with AppleScript, I ended up with the following script.
There was a need for some ”fine tuning” to deal with problems of Terminal app
scripting without manually changing preferences of Terminal app (problems
include that in certain cases more than two windows are created instead of one
and that it is not trivial to close (only) the correct window after quitting R
under the default settings of terminal).
-----------------
property commandString : "R --no-save --no-restore; screen osascript -e 'tell
application \"Terminal\" to close (every window whose name contains \"Survo
R\")'; exit 0"
tell application "System Events"
if (count (processes whose name is "Terminal")) is 0 then
tell application "Terminal"
activate
do script commandString in window 1
tell window 1
set custom title of first tab to "Survo R"
end tell
end tell
else
tell application "Terminal"
activate
do script commandString
set currWin to index of first window
tell window currWin
set custom title of first tab to "Survo R"
end tell
end tell
end if
end tell
-----------------
The script can be run in AppleScript editor (located in
/Applications/Utilities/AppleScript Editor), but for the actual use it is
useful to File->Export it to Application. Created app works just like any other
Mac OS X application and you can drag it to the dock to get the functionality
to launch command line R with one click.
It is certainly unnecessarily complicated for novice users to create the app
themselves, so the distribution of the final app (instead of the script) would
probably be a more reasonable idea. It is also likely that there are better,
safer and more portable ways to provide such a functionality (across Mac OS X
versions), but at least the basic idea can be tested with the script above.
So, finally, my question is: Would it be a possible and maybe even a good idea
to include this kind of Rterm shortcut app functionality to the R binary for
Mac OS X distribution or to make it available from some of the official R Mac
OS X pages?
Best wishes,
Reijo Sund
_______________________________________________
R-SIG-Mac mailing list
[email protected]
https://stat.ethz.ch/mailman/listinfo/r-sig-mac