[ESS] Sweave helper function

Andrew Robinson A.Robinson at ms.unimelb.edu.au
Thu Nov 1 04:46:13 CET 2007


Hi ESS-ers,

I find that in using Sweave the thing that I forget most often is how
to set up the graphics environment properly.  Inevitably I go back
through old files to remind myself.  Well, no more!  I have added the
following function to my .emacs file:

(defun ess-insert-Sweave-figure ()
   "Insert Sweave Figure into the buffer at next line."
   (interactive)
   (insert "
<<label=myfig-code, include=FALSE>>=

@

\\begin{figure}[!h]
\\centering
<<fig=TRUE, echo=FALSE, eval=TRUE, width=6, height=6, label=myfig>>=
<<myfig-code>>
@
\\caption[]{}
\\label{fig:myfig}
\\end{figure}

")
)

(define-key noweb-minor-mode-map "\M-nf" 'ess-insert-Sweave-figure)





My questions are 

1) does anyone know how I could hack this so that if a region were
marked, that region would be used as the seed of the labels?  I guess
I want to grab the marked region as an argument, and use that instead
of myfig everywhere above.

2) is this overkill?  Is there a more emacs-y way of solving my
problem?

Thanks for any thoughts!

Andrew

-- 
Andrew Robinson  
Department of Mathematics and Statistics            Tel: +61-3-8344-9763
University of Melbourne, VIC 3010 Australia         Fax: +61-3-8344-4599
http://www.ms.unimelb.edu.au/~andrewpr
http://blogs.mbs.edu/fishing-in-the-bay/




More information about the ESS-help mailing list