Evaluating code in .Rnw (R/tex) buffers

Stephen Eglen eglen at pcg.wustl.edu
Tue Mar 26 20:59:15 CET 2002


Hi,

I have recently started using Sweave, the R/S package by Friedrich
Leisch that allows R and LaTeX code to be intermixed in the same
document.  It is a very nice package, if you've not seen it
(http://www.ci.tuwien.ac.at/~leisch/Sweave).

Has anyone else started using ESS for writing .Rnw files?  If so, I
had a couple of questions:

1.  Everytime the point jumps out of a code chunk, the major mode
correctly switches from R to LaTeX.  In the same buffer, if I return
into a code chunk, and evaluate a line of code (using
e.g. ess-eval-line-and-step), I am again asked which "Process to load
into:".

For example, do "M-x R" then load the following into a file,
e.g. test.Rnw:
----------------------------------------------------------------------
% -*- mode: noweb; noweb-default-code-mode: R-mode; -*-
\documentclass[12pt]{article}

\begin{document}

Some \LaTeX code
<<>>=
rnorm(3)
@

Another chunk
<<>>= 
2+5
@ 
\end{document}
----------------------------------------------------------------------

If I put point on the "rnorm" line, then M-x ess-eval-line-and-step, I
am prompted which process to send the line to, before the line is
evaluated.  If I move out of that chunk and then back in, it will then
ask me again which process I want to send the line to.

It seems that everytime I re-enter the code chunk, the variable
ess-local-process-name is reset to nil.  This happens since the
variables in S-editing-alist get reset to the cdr.  In the case of
ess-local-process-name name, there is no "default value", so if it
already has got a value, perhaps it should keep that value, rather
than being reset to nil?

So, my suggestion is to test within ess-setq-vars-local that cdr of
each alist entry is non-nil before setting the value:

(defun ess-setq-vars-local (alist &optional buf)
  "Set language variables from ALIST, in buffer BUF, if desired."
  (if buf (set-buffer buf))
  (mapcar (lambda (pair)
	    (make-local-variable (car pair))
	    (if (cdr pair)	;; add this test?
		(set (car pair) (eval (cdr pair)))))
          alist)
  (ess-write-to-dribble-buffer
   (format "(ess-setq-vars-LOCAL): language=%s, dialect=%s, buf=%s, comint..echoes=%s, comint..sender=%s\n"
           ess-language ess-dialect buf comint-process-echoes comint-input-sender)))


2.  Has anyone else got any shortcuts for running Sweave on the
current .Rnw buffer?  At the moment, once I've finished editing the
.Rnw file, I switch to the *R* buffer and then run the command:

> Sweave("chap1.Rnw"); system("latex chap1")

So, if anyone had any suggestions on keybindings/approaches, I'd be
glad to hear of them.


Best wishes,
Stephen Eglen

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
ess-help mailing list -- To (un)subscribe, send
subscribe	or	unsubscribe
(in the "body", not the subject !)  To: ess-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the ESS-help mailing list