[ESS] ESS in brew syntax files
cberry at tajo.ucsd.edu
cberry at tajo.ucsd.edu
Mon Sep 12 07:07:53 CEST 2011
Michael Hannon <jm_hannon at yahoo.com> writes:
> "cberry at tajo.ucsd.edu" <cberry at tajo.ucsd.edu> writes:
>
>> Michael Hannon <jm_hannon at yahoo.com> writes:
>>
>> > Hi, Sven. Have you considered using the Babel feature of Emacs Org-Mode?
>> >
>> > http://orgmode.org/worg/org-contrib/babel/intro.html
>> >
>> > -- Mike
>>
>> Mike,
>>
>> FWIW, I use something like this:
>>
>> * Example
>>
>>
>> #+results: sample2
>> #+begin_src latex :eval never :exports none
>> Start with three letters: <%=sample(letters,3)%>,
>> Then go for three numbers: <%=sample(0:9,3)%>.
>> #+end_src
>>
>>
>> #+begin_src R :var txt=sample2 :results output org :exports results
>> require(brew)
>> brew( text=sub( "\n[ ]+", "\n", txt) )
>> #+end_src
>>
>>
>> Then I can edit the brew script in AucTeX-mode and export to ascii or
>> latex or whatever.
>>
>> But maybe there is a slicker way to do this.
>>
>> ??
>
> Hi, Chuck. Let me first of all state that I'm not the guy you should be using
> as a reference for Emacs Org-Mode, although I have been using it a bit lately.
>
> I'm not sure what the "brew" stuff adds in the above. If I have the following
> in a .org file:
>
> #+BABEL: :session *R*
>
> * Example
>
> #+begin_src R :results output :exports results
>
> tl <- sample(letters, 3)
> tn <- sample(0:9, 3)
> cat ("Start with three letters: ", tl, "\n")
> cat ("Then go for three numbers: ", tn, "\n")
>
>
> #+end_src
>
> then I can run the command "org-export" (bound to C-c C-e) to export directly
> to ASCII, DobBook, HTML, LaTeX, PDF, etc. I don't need the "brew" step, and I
> don't need the "output org" step. I can also intermix (using other
> "begin_src" blocks) LaTeX code, HTML code, Python code, etc., in the same file
> and have it all integrated into the final, exported document.
>
> Perhaps I'm missing the obvious?
That was intended as an ECM[1] of how to mix ESS and other editting
modes in a single document and use one of the other modes to edit the
brew syntax. Maybe I coulda used 'Hello World' instead.
Why did I bother?
The OP said
OP>> I am looking for a way to use ESS in files containing brew template
OP>> syntax. So, to have ESS mode in the R code chunks, like in Sweave
OP>> files with Rnw-mode. For those of you who do not know brew template
OP>> syntax yet, I attach an example below.
which I took to be a plea for better editting capability for the brew
part.
>From my POV, babel works well for mixing multiple language chunks and
editting them in modes like auctex-mode for latex, sgml-mode for html,
etc. And I thought the OP might get something from an ECM of how that
can be done. I posted it as a followup to your mention of babel, because
I felt some further explanation of how to marry brew syntax and R code
in org-mode was needed.
There is nothing done in brew that could not be done with other tools in
R. The advantage of brew is that the structure of a complex document can
be made transparent --- making it easier to create, edit, and
extend.
You could use cat() lines to emulate what is done at this link:
http://www.r-bloggers.com/brew-creating-repetitive-reports/
converting 'population.brew' to R code.
But that is still a pretty simple document. Even so, I suspect that the
resulting R code that you would produce would be hard to read, maintain,
and extend. Making it more complex, adding pieces that depend on
conditionals (if or switch) and pieces within them that depend on other
conditionals, and so on could get really messy as a collection of
cat()s.
But it would be pretty simple to copy 'population.brew' from that link
(starting after the 'maketitle' [sic] line) into a latex src block, put
the R code there into R src blocks (with minor tweaks), and you would have
something that is fairly easy to edit, maintain, and extend.
And if you wanted html in addition or instead, copying 'population.brew'
to an html block and editting it in sgml-mode seems to me to be an
easier route than editting literal strings in R.
Or you could create an org-mode version of 'population.brew' to allow
exports by many of the methods you mentioned above, but that is another
story.
HTH,
Chuck
[1] ECM is French for Exemple Complet Minimal (= Minimal Complete
Example), ref. http://thread.gmane.org/gmane.emacs.orgmode/16375/focus=16453
>
>
> -- Mike
> [[alternative HTML version deleted]]
>
> ______________________________________________
> ESS-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/ess-help
--
Charles C. Berry
UC San Diego
More information about the ESS-help
mailing list