[ESS] running Stata SE 8.2 using ESS on Mac OSX

Bill Rising brising at louisville.edu
Fri Nov 5 18:14:11 CET 2004

On Nov 5, 2004, at 11:36, Tak Wing Chan wrote:

> Hello
> Thanks ever so much for the replies and suggestions of many colleagues.
> I haven't got very far testing out things yet. But here is a summary 
> of my experience:

Here is an elisp function which will send the contents of the region to 
StataSE for evaluation (note that the part after do-applescript is 
supposed to be one massively long line.):

(defun ado-send-region-to-Stata ()
   (copy-region-as-kill (point) (mark))
   (do-applescript "try \r tell application \"Finder\" \r set theDummyDo 
to (((path to desktop folder) as text) & \"eraseme.do\") \r set 
theContents to the clipboard \r if not (the last character of 
theContents = return) then \r set theContents to theContents & return 
\r end if \r end tell \r try \r set the open_target_file to open for 
access file theDummyDo with write permission \r set eof of the 
open_target_file to 0 \r write theContents to the open_target_file 
starting at eof \r close access the open_target_file \r on error \r try 
\r close access file theDummyDo \r end try \r end try \r tell 
application \"StataSE\" \r activate \r open file theDummyDo \r end tell 
\r on error error_message number error_number \r return \"Error: \" & 
error_number & \". \" & error_message & return \r end try"))

If you like, you could put the following function into a where emacs 
will find it (like in your .emacs file) and then (after it is loaded) 
you can use
M-x ado-send-region-to-Stata
to send stuff to Stata.

If you use Stata instead of StataSE, change the \"StataSE\" to \"Stata\"

Note that this has a side-effect of creating a file called eraseme.do 
on the desktop. This is a bad thing, but is there for error checking, 
for now. Note also, that it will give a cryptic error in emacs (Wrong 
type argument:...) if there is no region. This is also bad, but I'll 
fix when I've time over the weekend.

This is a very primitive first pass, so it is not flexible... it will 
be put into my ado-mode over the weekend in a nicer fashion. I'm 
sending it along here, so that the ESS gurus can make some use of it if 
they please.

The script is based on the handler for writing a file which is 
available from Apple's website.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2373 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/ess-help/attachments/20041105/66504ef2/attachment.bin>

More information about the ESS-help mailing list