[ESS] \Sexp{} problem, how to add syntax="SweaveSyntaxNoweb" option to M-n s?

Charles C. Berry cberry at tajo.ucsd.edu
Tue Mar 23 21:30:48 CET 2010

On Tue, 23 Mar 2010, Marc Schwartz wrote:

> On Mar 23, 2010, at 7:20 AM, Werner W. wrote:
>> Hi,
>> I am currently getting into Emacs & ESS on Windows and it starts to 
>> feel like a very nice environment to program in R and Sweave. However, 
>> I have a little problem: is it possible to add the option 
>> syntax="SweaveSyntaxNoweb" to the issued command when pressing M-n s? 
>> Right now I always get an "Undefined control sequence" error from the 
>> latex compiler since Sweave is not replacing the \Sexpr{} command at 
>> all. I know that this is no problem when I add the above option. I 
>> looked at the ess-swv.el file but could figure out how to add an 
>> option. It would be great if someone had a hint towards the solution 
>> for me.

I doubt that this solves the problem with \Sexpr{}, but you can copy

ess-swv-run-in-R into your .emacs file , (possibly) rename it,  and edit 
the line

 	"local({..od <- getwd(); setwd(%S); %s(%S); setwd(..od) })"

to add whatever options you want. I use this strategy to force use of the 
weaver() driver:

        "local({..od <- getwd(); require(weaver);setwd(%S); %s(%S,driver=weaver()); setwd(..od) })"

which command I renamed 'ess-swv-run-weaver-in-R'. Then with

(defun ess-swv-weave-weaver ()
    "Run Sweave on the current .Rnw file."
    (ess-swv-run-weaver-in-R "Sweave"))

(define-key noweb-minor-mode-map "\M-n\M-s" 'ess-swv-weave-weaver)

I can type M-n M-s and force use of the weaver driver

>> Thanks so much,
>>  Wern
> Typically, when the \Sexpr's are not being evaluated, that is being 
> replaced with a scalar, it is an indication that the sweave.sty file is 
> not being found, as it is in that file, that the relevant code is 
> located.


> cat("Select a letter:\\Sexpr{sample(letters,1)}\n",file="oneLetter.Rnw")
> Sweave("oneLetter.Rnw")
Writing to file oneLetter.tex
Processing code chunks ...

You can now run LaTeX on 'oneLetter.tex'
> readLines("oneLetter.tex")
[1] "Select a letter:r"
> Sweave("oneLetter.Rnw",syntax="SweaveSyntaxNoweb")
Writing to file oneLetter.tex
Processing code chunks ...

You can now run LaTeX on 'oneLetter.tex'
> readLines("oneLetter.tex")
[1] "Select a letter:g"

\Sexpr{} inserts the result into the tex file with either the default 
options or syntax="SweaveSyntaxNoweb"

And I get a similar result when I open oneLetter.Rnw with emacs and type 
M-n s.

Does Sweave.sty really figure into this??



> You can either manually add the \usepackage{PATH.TO.SWEAVE/Sweave.sty} directive to your .Rnw file's preamble, or see the Details section of ?RweaveLatex for information on other configuration options.
> HTH,
> Marc Schwartz
> ______________________________________________
> ESS-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/ess-help

Charles C. Berry                            (858) 534-2098
                                             Dept of Family/Preventive Medicine
E mailto:cberry at tajo.ucsd.edu	            UC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/  La Jolla, San Diego 92093-0901

More information about the ESS-help mailing list