[ESS] Beginner: ESS, Sweave - process selected region
tuechler at gmx.at
Mon Mar 14 18:01:08 CET 2005
a week ago I asked for a possibility to pass a region of a Snw-file to R.
Since surprisingly no one seems to have in use such a function I tried to
adapt one of those David Whiting posted some time ago.
The function I imagine would stangle a selected region of a Sweave-file and
execute the R-commands.
As I have no experience with Emacs-Lisp I could only sketch a very crude
one. I did try it a little and at first sight it seems to work. I poste it
here, hoping that some expert may suggest a better solution.
Please remember, this is far from a tested function for routine use. For
example it may delete an existing file ("stangle_temp").
(defun ess-stangle-region ()
"copy region in temp-file, stangle and source"
(setq stangle-filename "stangle_temp") ; name for temp-file
; delete temp-file befor every new execution
(if (file-exists-p stangle-filename)(delete-file stangle-filename))
(append-to-file (region-beginning) (region-end) stangle-filename )
(setq ess-command (format "Stangle (%S) " stangle-filename))
(ess-execute ess-command 'buffer nil nil) ;stangle temp-file
(setq stangle-filename-r (concat stangle-filename ".r"))
(setq ess-command (format "source (%S) " stangle-filename-r))
(ess-execute ess-command 'buffer nil nil) ;execute stangled file
Xemacs 21.4.13, ESS 1.12, Windows98
More information about the ESS-help