[ESS] Code contribution or suggestion
Steve Lianoglou
mailinglist.honeypot at gmail.com
Thu Jun 30 17:11:16 CEST 2011
Hi Jim,
Unless I'm missing something, an alternative way to achieve your
templatings stuffs that you've got here is to use yasnippet:
http://code.google.com/p/yasnippet/
You can setup templates rather easily for various languages (not just
sweave), and making new templates are pretty easy (no elisp required
:-)
Here's a video of it in action:
http://www.youtube.com/watch?v=76Ygeg9miao
The first ~ minute is how to install it, which you can skip if you're
in a hurry and just want to check it out.
Hope that helps,
-steve
On Fri, Jun 24, 2011 at 11:10 AM, <Jim_Garrett at bd.com> wrote:
>
> Hi all,
> I have just joined this list. I've been using Emacs and ESS for years but
> only recently have I begun learning e-lisp and customizing Emacs. I've also
> just begun using Sweave consistently. I manage several other statisticians,
> and I'm training them on Sweave so that we may use it for all critical
> reports. Along the way, I've taken some steps to automate the generation of
> boilerplate text in standard, common cases. This has made it much easier to
> use Sweave, partly by reducing typing and partly to keep me from having to
> remember options. This may be a form of dumbing-down but it does help one
> to get started quickly.
> I'd like to contribute some e-lisp functions I've written for possible
> inclusion in ESS. They would be trivial for any experienced e-lisp
> programmer to write, so I guess I'm actually asking that something along
> these lines be included to help beginners set up Sweave documents. (Or is
> something equivalent already there?) I'm using ESS 5.10-1, Emacs 23.1.1,
> all from Ubuntu's repositories.
> Specifically, here are the things I've automated:
> 1. Generating a skeletal LaTeX document with a standard preamble..
> 2. Creating a skeleton for an Sweave code chunk that creates a figure.
> 3. Similarly, for a table (using xtable).
> 4. Similarly, for a code chunk that returns nothing (i.e., carries out
> necessary data processing but does not directly add to a report)
>
> Below are my functions. Feel free to make whatever modifications you feel
> necessary, or to achieve these ends by other means.
> Best regards,
> Jim Garrett
> Baltimore, Maryland, USA
> 1. To generate a template for a LaTeX file:
> (defun create-sweave-file ()
> "Insert contents of template file into buffer."
> (interactive nil)
> (insert-file-contents "~/.sweave-template.rnw"))
> where .sweave-template.rnw is
> \documentclass[english]{article}
> \usepackage[T1]{fontenc}
> \usepackage[latin9]{inputenc}
> \usepackage{babel}
> \begin{document}
> \title{}
> \author{}
> \date{}
> \maketitle
> \end{document}
> I actually include more in the skeleton because I encourage a particular
> report format for my group, but I don't want to inflict those on everyone.
> 2. To create a template for a code chunk that creates a figure:
> (defun insert-sweave-figure (label)
> "Insert standard figure stuff and R tags."
> (interactive "MEnter label: ")
> (insert
> (concat
> "\\begin{figure}
> \\begin{center}
> <<" label ", fig = T, echo = F>>=
> @
> \\end{center}
> \\caption{}
> \\label{fig:" label "}
> \\end{figure}")))
> (I like to leave 3 blank lines in the code block so that I can edit the
> middle one, leaving one above and below so it doesn't look crowded.)
> 3. To create a template for a code chunk creating a table, using xtable:
> (defun insert-sweave-table (label)
> "Insert code that creates a LaTeX table through the xtable function."
> (interactive "MEnter label: ")
> (insert
> (concat
> "<<"
> label
> ", echo = F, results = tex>>=
> require(xtable)
> print(xtable(,
> caption = \"\",
> label = \"tab:"
> label
> "\"),
> include.rownames = F)
> @")))
> 4. To create a template for a code chunk that returns no output:
> (defun insert-sweave-code (label)
> "Insert code block that produces no output."
> (interactive "MEnter label: ")
> (insert
> (concat
> "<<"
> label
> ", echo = F, include = F>>=
> @")))
> -----------------------------------------
> *******************************************************************
> IMPORTANT MESSAGE FOR RECIPIENTS IN THE U.S.A.: This message may constitute
> an advertisement of a BD group's products or services or a solicitation of
> interest in them. If this is such a message and you would like to opt out of
> receiving future advertisements or solicitations from this BD group, please
> forward this e-mail to optoutbygroup at bd.com.
> *******************************************************************This
> message (which includes any attachments) is intended only for the designated
> recipient(s). It may contain confidential or proprietary information and may
> be subject to the attorney-client privilege or other confidentiality
> protections. If you are not a designated recipient, you may not review, use,
> copy or distribute this message. If you received this in error, please
> notify the sender by reply e-mail and delete this message. Thank you.
> *******************************************************************
> Corporate Headquarters Mailing Address: BD (Becton, Dickinson and Company) 1
> Becton Drive Franklin Lakes, NJ 07417 U.S.A.
> ______________________________________________
> ESS-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/ess-help
>
--
Steve Lianoglou
Graduate Student: Computational Systems Biology
| Memorial Sloan-Kettering Cancer Center
| Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact
More information about the ESS-help
mailing list