[ESS] iESS[Stata] quirks

Brendan Halpin brendan.halpin at ul.ie
Wed Oct 15 21:58:15 CEST 2008

Rodney Sparapani <rsparapa at mcw.edu> writes:

> 1) the #delimit command can only be used in .do files.  But, of
> course, I may want to step through a .do file with iESS.  However,
> since the #delimit command is not allowed then, it can be painful.
> Ok, this was a dumb design on Stata's part; I'll grant you.  But,
> maybe iESS[Stata] could watch for a '#delimit ;' command and then
> handle the input accordingly, i.e. split the input at ';' and send
> each part as
> a single line.

My practice with Stata is to execute the current command or region by
(1) writing it to a file (2) prepending it with "#delimit ;" if
necessary and (3) sending a "do file.do" command to Stata. It works
reasonably well, but is a bit more simplistic than your suggestion of
parsing the input and translating it on the fly to the interactive
format (what is missing but implicit in your description is the notion
that multi-line commands need to be put on a single line). 

For the record, this is in my ess-local.el:

(defun delimit-do (clear &optional b e)
  "Send the region (or B to E) to the Stata process, via a do file.
If \"#delimit ;\" occurs in the current buffer above the start of the region,
wrap the commands in \"#delimit ;\"/\"#delimit cr\". 

Stata treats code in a do-file differently from interactive code;
this mode allows \"/* ... */\" style comments as well as changing
the delimiters."
  (interactive "P")
  (ess-force-buffer-current  "Process to load into: ")
  (if (null b) (setq b (region-beginning)))
  (if (null e) (setq e (region-end)))
    (let ((commands (buffer-substring-no-properties b e))
          (delimit-do-filename (concat 
                                (file-name-directory (buffer-file-name (current-buffer)))
      (goto-char b)
      (setq delimit (re-search-backward "^#delimit +;" nil t))
      (set-buffer (find-file-noselect delimit-do-filename))
      (delete-region (point-min) (point-max))
      (if clear (insert "clear\n"))
      (if delimit (insert "#delimit ;\n" 
                          "\n#delimit cr\n")
        (insert commands "\n"))
      (write-file delimit-do-filename nil)
       (get-ess-process ess-current-process-name)
       (format "do %s \n" delimit-do-file)))))

It works for me, but it is a bit fragile -- notably it is pretty naive
about how it tests whether "#delimit ;" is in effect. Also, the
inclusion of the trailing "#delimit cr" is superfluous.

Brendan Halpin,  Department of Sociology,  University of Limerick,  Ireland
Tel: w +353-61-213147 f +353-61-202569 h +353-61-338562; Room F2-025 x 3147
mailto:brendan.halpin at ul.ie  http://www.ul.ie/sociology/brendan.halpin.html

More information about the ESS-help mailing list