This page offers help and discussions about how to make AlphaX and Alphatk interact with the statistical package R using AlphaTcl's S+/R mode under Mac OSX.
Alpha contains a so-called S+/R mode that supports the writing of S+ or R scripts (text files with either extension '.s' or '.R') as also briefly described at R and external applications. On some platforms such as the Macintosh this mode also conveniently supports the sending of these scripts to the GUI application of R, where the script is executed and the wanted results are immediately generated. This enables a very powerful use of R.
Alpha's S+/R mode supports in general the editing of S+ or R scripts from within Alpha. This offers the user syntax specific editing, including the coloring of language specific keywords, assists the programer by providing templates and context-aware help, including the jumping to help pages such as those offered by the R-community on the internet. On some platforms such as the Macintosh the S+/R mode also conveniently supports the sending of these scripts to the R GUI application, where the script is immediately executed and the wanted results are generated. This enables a very recommendable and powerful use of R.
The original Alpha was initially developed for the Mac OS Classic platform and only later for other platforms such as Windows (AlphaTk). In the transition to Mac OS X the S+/R mode ceased to work realiably. Many of the contributions to the discussions you find below are from these days. Fortunately all these difficulties are gone and as of this writing I, i.e. Andreas Fischlin <af>, made a little effort to fix the difficulties with the last official release of AlphaX, i.e. Version 8.02. Moreover, with the help of Bernard Desgraupes and others from Alpha Cabal, I improved the S+/R mode to conform fully to latest AlphaTcl features. The fully uptodate mode is now also offered as part of the latest beta development release (AlphaX 8.2b) of AlphaX that can be downloaded from AlphaX Development Binaries.
Acknowledgment: Initially this page was created by original authors of the S+/R mode of Alpha, notably Craig Barton Upright and others while they learned how to use R. Craig thought that the information that he gathered might be useful for other users and developers. I decided to and add some more uptodate hints on how to work with the S+/R mode and to retain these older contributions, since one or the other detail might still be useful (In the older discussions below, <cbu> are comments from Craig Barton Upright, and <tlw> are comments from Tony Leroy Westerling).
Feel free to add to this discussion, but please try to help keep this a coherent document that one can read straight through (and be sure to identify yourself with some consistent moniker).
Sections below include
Latest information (added by <af> as of 12.Sep.2009):
Downloading, Installing R
This has become very straightforward: Download it from R for Mac OS X, install it the usual Mac way by using the easy install option and resort to the instructions provided at R's FAQs web site and/or FAQs for Mac OS X should you encounter difficulties.
Fixing the S+/R mode in last official release of AlphaX v 8.02
If you use the last official release of Alpha (AlphaX v 8.02) the S+/R mode is broken and needs fixing. The fix is simply a mode-specific preference file, that you can download from our RAMSES download website. The file 'SPrefs.tcl' needs to be installed by following these steps:
Note, however, this fix assumes you are using only one R version at a time on your system and that you are using a rather modern R GUI application.
In all other cases, for instance, should you wish to use several R versions in parallel, e.g. by assigning R 1.7.1 (last carbon version) as the S+ application as well as a more recent R version as the R application from within the S+/R mode, then the fix will not work reliably under all circumstances. In such a case I strongly recommend to use a more recent AlphaX with the latest S+/R mode. Any beta development release (AlphaX 8.2b) contains a fully featured S+/R mode that offers many new features and supports the simultaneous use of R 1.7.1 and more modern versions of R (as of this writing (19.Aug.2009) I have tested this for S+/R mode v 2.5.2 running within AlphaX 8.2b13, using R 1.7.1 as the S+ application and R 2.9.1 as the R application under Mac OS X 10.5.8 (Leopard) on an Intel Mac).
Using the 'S+/R'' mode in latest beta development release (AlphaX 8.2b)
This should be a very straightforward experience and the latest 'S+/R'' mode is preinstalled and should be ready for immediate use. In addition to previously available functionality you should also be able to enjoy shortcut customization and other new features.
Below you find the initial discussions on this topic likely being outdated, but you may still find some useful hints here and as of this writing (19.Aug.2009) I therefore decided to retain these discussions for the time-being <af>
Initial Request For Help
<tlw> I am a new Alpha user, trying to use R-mode in AlphaX 8.0b8 on a G4 running OS X 10.2.5. My R package is installed via Fink, so the R binary resides in /sw/bin/
I am having problems selecting my R application in S-mode preferences. I went to
Config:S Mode Prefs:Preferences:Page 2:RSig
and clicked the "set" button.
R does not show up in the list of applications found (Alpha is looking in usr/bin?)
So, I selected "locate manually" and "communicate via the command-line" and click the "set" button.
Then I navigate to /sw/bin in the pop up window, select "R", and click on "open"
Page 2 of my Preferences for 'S' mode window now says
RSig -- Unknown application with sig '/sw/bin/R'
when I select some R code in an open Alpha *.R file and attempt to send the commands to R via the S+/R menu, I get the following error message:
Can't find app w/ sig "/sw/bin/R". Try rebuilding your desktop or changing your helper apps.
Can anyone tell me what is going wrong here?
Note that /sw/bin/R works just fine if typed from the command line in X11 or terminal.app.
I also tried creating a soft link to R in the /usr/bin directory, but interestingly the S mode configuration menu does add R to the list of applications found.
<cbu> Hi, Tony, I'm the current maintainer of 'S' mode. I originally created it using OS 8.1 for Alpha 7.3 . I then started using Stata for most of my statistical analysis, and haven't really tested later versions of R, Alpha, and definitely not OSX for the interaction between Alpha and the app.
There are some known issues with setting 'helper' applications in OSX that haven't been adequately addressed yet, and your problem might lie there, but I really should take a look into this further and will try to do so soon. btw, there is a bug report in 'bugzilla' [http://www.maths.mq.edu.au/~steffen/Alpha/bugzilla/show_bug.cgi?id=642] that addressed a similar issue with R and Alphatk, which I was never able to deal with because I was using OS 9.2 exclusively, but now that I have 10.2.5 available hopefully I can deal with that at the same time -- if the issue isn't identical, it is at least related.
Downloading, Installing R
<cbu> If you wouldn't mind, could you give me whatever the current R download links are, esp for OSX?
<tlw> I am using the latest version of R for MacOS X (Darwin/X11) maintained by Jan de Leeuw and Sefano M. Iacus. You can get the base package and about 300 additional packages on a compressed disk image with installer at
http://gifi.stat.ucla.edu/pub (this is the CRAN distribution)
or you can install the base packages using FINK if you prefer.
I believe both install version 1.7.0
<cbu> I downloaded R using the site that you directed me to, and I went through the installation process, and was told that installation was successful, but I can't find any trace of R on my hard drive! Any clues for me? I have to admit that I'm fairly new to OSX, and don't really have the file structure figured out yet.
<tlw> OS X has essentially the same file structure as Unix, with Mac stuff added on top. Please forgive me if the following information is more detailed than necessary.
<cbu> No forgiving is necessary. I am old enough that my first computing experiences were with unix, and when I re-entered academia many years later I found that experience invaluable, but I never had to do any sort of sysadmin stuff and I was always grateful. I used X11 quite a bit when I started grad school in Princeton's Sociology department, mostly with emacs and S-Plus, but gradually was lured away by Macintosh, especially when I discovered Alpha -- I found myself using the ftp menu quite a bit to edit all of my *.s (and later my *.do and *.sas ...) files using Alpha, and then processing them all from my unix account via a telnet window. It was (and still is) a really slick way to get a decent editing interface for all of these files -- which is why I spent so much time creating these statistical modes -- and then process them all with unix command lines.
<tlw> I'm not sure which site you installed R from, since I mentioned two different sources (cran and fink).
If you downloaded the "official" cran dmg, then your R executable should be
The R libraries and documentation will be in
If you used Fink to install the base package instead, then your R executable will be
and the libraries will be at
If you used Fink to install R, you will need to add
to your .cshrc or comparable file in your home directory. Files starting with "." are hidden from the finder, but you can view them in shells launched from Terminal.app or xterm in X11 with the usual unix
(followed by a <return>, true for all other commands listed below).
<cbu> I understand the basic unix commands like cd and ls and the concept of hidden files, but OSX still baffles me. Mostly because I haven't spent enough time trying to figure it all out, partly because in general I don't need to and I try to surround myself with tools (like Alpha!) that take care of everything for me. I'm afraid that I still need a little primer on how to navigate the file system...
<tlw> When you are logged in as Craig or whatever, your home directory is /Users/Craig . If you open a shell in the Terminal app (in Applications/Utilities), any time you type just
you will be in your home directory. If you type
you will see all the Mac user directories like Documents, Downloads, Music, etc., the same as what you get when you hit the home icon on a finder window. Type
and you will see something like
So go up two levels to the root directory by typing
and then type "ls" and you will see the Applications and Applications (Mac OS 9) directories and a bunch of directories that are mostly hidden from searches with the Finder. Most of these folders are owned by system rather than a user, and maybe Finder ignores them?
In a system like this, your personal files (work, docs, etc) will be in /Users/Craig . Non-system application binaries will often be installed to
Their libraries go to
Fink manages thousands of software packages, and installs them to
which helps to keep them straight.
You don't have to use the terminal app or xterm to view these files. If you open a finder window (just click once on your desktop and then hit apple-n) you can see these directories by hitting apple+shift+g to get a dialogue box Go to folder: and then type in
and you will see the directories with the R documentation and packages.
If you want to change something in these directories, you can preface commands in a shell with sudo and type in your password each time, or you can use the Finder to navigate to the directory and file you want to mess with, hit apple+i to get its information, and then click on Ownership & Permissions and change the owner from System to Craig (I would change it back again after) or log in as root. To enable root login, launch NetInfo Manager in your Applications/Utilities folder and use Enable Root User in the Security menu.
<cbu> Found them! Thanks!!!
Launching R from a Terminal Window
<cbu> I'll assume that there is nothing that I can simply open with double-clicking in order to start R (?) ... the sort of thing that would give me much fewer headaches.
<tlw> I am assuming you have downloaded and installed the beta X11 and SDK from
as well as the developer's tools cd that comes with mac os x, and have used FINK or something similar to install system-xfree86 (this puts an xfree86 wrapper around Darwin and X11)
<cbu> Well, I don't know if I have the developer tools or not, and I didn't explicitly install anything but X11.
<tlw> If you add
if (! $?DISPLAY) then setenv DISPLAY :0.0 endif
to your .cshrc file as well, then you can launch x11 apps from shells opened via the Terminal.app (in Applications/Utilities), which is more user friendly than an x11 window. So, for example, you can start an R session in a shell from Terminal.app (with scroll bar, etc), and then open an graphics window by typing
at the R prompt. You want to be able to do something like this to test your R application independently of AlphaX.
By the way... To just run R installed from CRAN, you might not need system-xfree86 installed. You don't need the developers tools installed if you are just running R, but they will install a lot of tools you might rely on if you have been working in other flavors of Unix. You will need X11 and probably SDK for R to have the basic graphics capabilities. I had installed all of it already because I am using X apps like GIMP, so I was thinking R required all of that as well.
<cbu> Sorry, I have a terminal window open but I'm not sure how to start an R session. (Feeling really dumb here ...)
<tlw> Thanks for keeping after this. I just assumed all you "developer" types were unix hackers. Nice to know I can contribute something, even if I am only a month or so ahead of you on the learning curve.
If you haven't done so already, open a shell in your home directory (type
to make sure you are in your home directory) and then create a .cshrc file with the code to set your DISPLAY environment
My .cshrc looks like this:
###tony's .cshrc############## # set DISPLAY so that you can use Terminal.app to launch X apps if (! $?DISPLAY) then setenv DISPLAY :0.0 endif # Since I have a bunch of Fink binaries in /sw I have source /sw/bin/init.csh # These aliases let me navigate quickly alias work 'cd ~/Leroy/Work' alias proj 'cd ~/Leroy/Work/Projects' # These aliases force me to use secure shells when accessing # my other machines. They can be really irritating when trying # to connect to a machine that isn't running ssh # so you might not want to create these aliases alias ftp "echo '************ * use sftp'" alias telnet "echo '************ * use ssh'" alias rlogin "echo '************ * use ssh'" # This makes sure the CRAN R binaries are in my path set path = ($path /usr/local/bin /usr/X11R6/bin) ####################################
Now, to run R, open a shell with Terminal.app or with xterm from x11, and then type "R" <return> and you will launch an R session. Make sure it is a capital "R". Best would be to navigate to a directory you create for storing files related to your R test session.
You will be happier using Terminal.app than launching xterm from x11. An xterm window from xll is not going to have a scroll bar unless you add one, and cut and paste will not work like you are used to. If you have created a .cshrc file that sets your display environment like I describe above, you will be able to launch X apps from terminal shells, as long as you have launched X11 prior to opening the shell in Terminal. I just add X11 to my startup applications (see "login items" in the "personal" row of your system preferences dialogue).
<cbu> Thanks! I was able to launch R following the instructions that you gave above, in particular this line
set path = ($path /usr/local/bin /usr/X11R6/bin)
seemed to be what I needed -- plus knowing that R had to be a capital letter. (And that doesn't seem very unixy at all from my earlier experiences from the dark ages...)
Information on Fink
<tlw> You can add a great deal of functionality to your macintosh under os X 10.2.* if you are willing to spend a little time on the unix system basics. I would recommend the following place to start:
You can find everything you need to know from this web site to install Fink and Fink Commander, which you can then use to install and maintain thousands of open source packages to do just about anything...
Including "autocutsel", a nice little program that will make cutting and pasting between X11 and Mac apps easier.
Including a window manager...
Apple has its own window manager, quartz-wm, but it is not very easily configurable for x11. There are lots of window managers available that will allow you to customize everything. I don't use them yet myself... I have just installed the autocutsel, and use terminal.app or nice gui's as much as possible.
The web site I listed above will give you information on several window managers and on setting up autocutsel. In particular, if you decide to get into configuring x11 more to your liking, read
More Fink stuff...
Some other possible Fink enticements might be GIMP (open source graphics editor, free, puts Illustrator to shame) Ghostview (gv) and Ghostscript (gs) (let you view graphics and save them in many formats) free-civ (free, highly configurable multiplayer Civilization II clone), and so on...
<tlw> I have been screwing around with my AlphaX and have noticed the following:
AlphaX defaults to searching for binaries in /usr/bin, so it doesn't find R automatically, you have to do it manually.
If you edit "Exec Search Path" in Helper Applications Preferences to add /usr/local/bin or /sw/bin, it still does not find R, because...
AlphaX apparently does not like capitalized names for command line interface binaries. I tested this by adding a soft link to R in /usr/bin named lowercase "r" (cd /usr/bin; ln -s /usr/local/bin/R r), and AlphaX finds it automatically, unlike R. It still doesn't work, unfortunately.
I read that Alphatk can't always find an R process the first time you try to switch to it. The listed solution was start an R process from a shell, and then Alphatk should be able to find it thereafter. This does not work for AlphaX, and I tried installing Alphatk and testing it, and couldn't get it to work either.