[ESS-bugs] Some code suggestions
Jim_Garrett at bd.com
Jim_Garrett at bd.com
Wed Jun 22 20:50:35 CEST 2011
I have no bug report, but rather a modest code contribution or suggestion.
Lately I've begun using Sweave heavily, and I've found it helpful to
automate boilerplate generation for some things that recur frequently,
namely:
1. Generating a standard LaTeX preamble, etc.
2. Creating a skeleton for a code chunk that creates a figure.
3. Or a table (using xtable)
4. Creating a skeleton for a code chunk that returns nothing.
In essence, this saves me some typing, and also saves me from having to
remember all the options available. I'm sure one could complain that I
should memorize all the options, but I think automating some frequently-used
options can make Sweave more palatable to a non-expert user. I'm on the way
to requiring statisticians who report to me to use Sweave for all critical
reports, so ease of use is an important issue to me!
I've written some Emacs Lisp functions that do these. Clearly they're very
simple and would not take more than a minute for an experienced e-lisp
programmer, so I guess I'm really suggesting that some functions along these
lines be included (not necessarily mine). They've helped me a great deal
and would probably help others who are new to Sweave.
Here are my functions, for your consideration. Feel free to use them or
not, modify them, rename them, whatever.
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}
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}")))
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>>=
@")))
I've just signed up for the ess-help e-mail list and I hope to contribute in
the future. My Lisp expertise is growing, slowly.
Best regards,
Jim Garrett
Baltimore, Maryland, USA
-----------------------------------------
*******************************************************************
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.
More information about the ESS-bugs
mailing list