emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Converting Org to Sweave (*.Rnw)
@ 2012-07-17 12:19 Julian Gehring
  2012-07-17 16:05 ` cberry
  0 siblings, 1 reply; 4+ messages in thread
From: Julian Gehring @ 2012-07-17 12:19 UTC (permalink / raw)
  To: emacs-orgmode

Hi,

is there a way to convert Org-mode files with R code blocks to the 
Sweave ('*.Rnw') [1] file format or has anyone planned to work on this?

Sweave is heavily used in the R community in terms of literate 
programming, and has a tight integration into current package building 
workflows.  Essentially, the file format is a latex document, with 
designated code chunks.

Since Org/Org-babel offers a very similar feature set, and already 
covers the export to latex, I was wondering whether anyone is working on 
some code that would rewrite the code block headers in the export?  In 
the R community, I have seen a lot of interest in such an exporter, that 
would allow to write the documentation in Org itself and later export it 
to several backends, including Sweave to integrate it in the R package.

If anyone has some comments regarding this or is interested in working 
on this, please let me know.  My colleagues and I would be very 
interested in contributing in projects in this direction.


Best
Julian


[1] http://en.wikipedia.org/wiki/Sweave

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Converting Org to Sweave (*.Rnw)
  2012-07-17 12:19 Converting Org to Sweave (*.Rnw) Julian Gehring
@ 2012-07-17 16:05 ` cberry
  2012-07-17 17:23   ` Julian Gehring
  0 siblings, 1 reply; 4+ messages in thread
From: cberry @ 2012-07-17 16:05 UTC (permalink / raw)
  To: emacs-orgmode

Julian Gehring <julian.gehring@gmail.com> writes:

> Hi,
>
> is there a way to convert Org-mode files with R code blocks to the
> Sweave ('*.Rnw') [1] file format or has anyone planned to work on
> this?

First, there is this thread:

       http://comments.gmane.org/gmane.emacs.orgmode/7931

and then there is this
    
    http://yihui.name/knitr/demo/org/

====

But I wanted more, and I think the new exporter provides some awesome
possibilities, so...

I have put together a rudimentary exporter for Sweave and for brew style
chunks and hope to have several of the knitr chunk flavors supported
soon. I've not looked closely, but I think pander can be supported, too. 

The basic idea is to use the new export engine. See

    http://orgmode.org/worg/dev/org-export-reference.html

for background.

The e-latex, e-html, and other modes are used as parent backends and
e-latex-rnw, e-html-brew, etc are *derived* backends. It is pretty easy
to hitch a ride on the work done to make a parent backend and then add a
minimal definition of the chunk formatting. 

The only tricky bit is getting Babel to help in the process, but not
interfere. I want Babel to porcess non-R src blocks and clean out R
#+RESULTS blocks, but not strip out the header args, as these may be
wanted (as you suggest below) to inform the chunk arguments. I've
managed this by advise'ing org-babel-exp-do-export to do special
handling of R src blocks.

I've not yet delved into translating the headers into code chunk
arguments. Some like 'width' seem pretty obvious. Others like the
:exports + :results translation may take some thought. And there are
some idioms in Sweave and kntir that have not corresponding idiom in org
(which is a strong motive for doing this work) like 'dev' in knitr as
well as ':cache yes' versus 'cache=T', which are false cognates, so to
speak

So far, what I've done is do add a header arg like this:

   Here is an inline chunk: src_R{ rnorm(1) } which the brew export
   renders as <%= rnorm(1) -%> (i.e. print the result, but do not place
   a line break after the result), making a non-printing version of this
   is done by using this src_R[ :ravel <% -%> ]{ rnorm(1) }, which
   renders as <% rnorm(1) -%>.

or this

:   #+name: aCachedChunk
:   #+begin_src R :ravel cache=T
:   x <- rnorm(1e7)
:   #+end_src

which is rendered as 

<<aCachedChunk, cache=T>>=
x <- rnorm(1e7)
@ %def

when using the Sweave style exporters.

However, Nicolas *just* added support for #+ATTR_SOMETHING, where
SOMETHING is a user defined key. And I incline to the view that using
something like

:   #+attr_ravel: cache=T
:   #+name: aCachedChunk
:   #+begin_src R 
:   x <- rnorm(1e7)
:   #+end_src

might be preferred.

Anyway, I'll try to get a version up where you can have a look at it
sometime today.

I am keen to collaborate on this.

Chuck


>
> Sweave is heavily used in the R community in terms of literate
> programming, and has a tight integration into current package building
> workflows.  Essentially, the file format is a latex document, with
> designated code chunks.
>
> Since Org/Org-babel offers a very similar feature set, and already
> covers the export to latex, I was wondering whether anyone is working
> on some code that would rewrite the code block headers in the export?
> In the R community, I have seen a lot of interest in such an exporter,
> that would allow to write the documentation in Org itself and later
> export it to several backends, including Sweave to integrate it in the
> R package.
>
> If anyone has some comments regarding this or is interested in working
> on this, please let me know.  My colleagues and I would be very
> interested in contributing in projects in this direction.
>
>
> Best
> Julian
>
>
> [1] http://en.wikipedia.org/wiki/Sweave
>
>
>

-- 
Charles C. Berry                            Dept of Family/Preventive Medicine
cberry at ucsd edu			    UC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/  La Jolla, San Diego 92093-0901

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Converting Org to Sweave (*.Rnw)
  2012-07-17 16:05 ` cberry
@ 2012-07-17 17:23   ` Julian Gehring
  2012-07-18  3:19     ` cberry
  0 siblings, 1 reply; 4+ messages in thread
From: Julian Gehring @ 2012-07-17 17:23 UTC (permalink / raw)
  To: emacs-orgmode

Hi Chuck,

thanks, what you describe seems to me like a already quite elaborated 
solution.  I would be very interested in your existing implementation 
for this.

As you mentioned, there will probably have to be a trade-off between the 
syntax/functionality of Org-mode/babel and Sweave.  But already a 
solution being able to handle to obvious cases of header argumnets would 
be step forward in bringing Org-mode even closer to R Sweave.


Best
Julian





























































On 07/17/2012 06:05 PM, cberry@tajo.ucsd.edu wrote:
> Julian Gehring <julian.gehring@gmail.com> writes:
>
>> Hi,
>>
>> is there a way to convert Org-mode files with R code blocks to the
>> Sweave ('*.Rnw') [1] file format or has anyone planned to work on
>> this?
>
> First, there is this thread:
>
>         http://comments.gmane.org/gmane.emacs.orgmode/7931
>
> and then there is this
>
>      http://yihui.name/knitr/demo/org/
>
> ====
>
> But I wanted more, and I think the new exporter provides some awesome
> possibilities, so...
>
> I have put together a rudimentary exporter for Sweave and for brew style
> chunks and hope to have several of the knitr chunk flavors supported
> soon. I've not looked closely, but I think pander can be supported, too.
>
> The basic idea is to use the new export engine. See
>
>      http://orgmode.org/worg/dev/org-export-reference.html
>
> for background.
>
> The e-latex, e-html, and other modes are used as parent backends and
> e-latex-rnw, e-html-brew, etc are *derived* backends. It is pretty easy
> to hitch a ride on the work done to make a parent backend and then add a
> minimal definition of the chunk formatting.
>
> The only tricky bit is getting Babel to help in the process, but not
> interfere. I want Babel to porcess non-R src blocks and clean out R
> #+RESULTS blocks, but not strip out the header args, as these may be
> wanted (as you suggest below) to inform the chunk arguments. I've
> managed this by advise'ing org-babel-exp-do-export to do special
> handling of R src blocks.
>
> I've not yet delved into translating the headers into code chunk
> arguments. Some like 'width' seem pretty obvious. Others like the
> :exports + :results translation may take some thought. And there are
> some idioms in Sweave and kntir that have not corresponding idiom in org
> (which is a strong motive for doing this work) like 'dev' in knitr as
> well as ':cache yes' versus 'cache=T', which are false cognates, so to
> speak
>
> So far, what I've done is do add a header arg like this:
>
>     Here is an inline chunk: src_R{ rnorm(1) } which the brew export
>     renders as <%= rnorm(1) -%> (i.e. print the result, but do not place
>     a line break after the result), making a non-printing version of this
>     is done by using this src_R[ :ravel <% -%> ]{ rnorm(1) }, which
>     renders as <% rnorm(1) -%>.
>
> or this
>
> :   #+name: aCachedChunk
> :   #+begin_src R :ravel cache=T
> :   x <- rnorm(1e7)
> :   #+end_src
>
> which is rendered as
>
> <<aCachedChunk, cache=T>>=
> x <- rnorm(1e7)
> @ %def
>
> when using the Sweave style exporters.
>
> However, Nicolas *just* added support for #+ATTR_SOMETHING, where
> SOMETHING is a user defined key. And I incline to the view that using
> something like
>
> :   #+attr_ravel: cache=T
> :   #+name: aCachedChunk
> :   #+begin_src R
> :   x <- rnorm(1e7)
> :   #+end_src
>
> might be preferred.
>
> Anyway, I'll try to get a version up where you can have a look at it
> sometime today.
>
> I am keen to collaborate on this.
>
> Chuck
>
>
>>
>> Sweave is heavily used in the R community in terms of literate
>> programming, and has a tight integration into current package building
>> workflows.  Essentially, the file format is a latex document, with
>> designated code chunks.
>>
>> Since Org/Org-babel offers a very similar feature set, and already
>> covers the export to latex, I was wondering whether anyone is working
>> on some code that would rewrite the code block headers in the export?
>> In the R community, I have seen a lot of interest in such an exporter,
>> that would allow to write the documentation in Org itself and later
>> export it to several backends, including Sweave to integrate it in the
>> R package.
>>
>> If anyone has some comments regarding this or is interested in working
>> on this, please let me know.  My colleagues and I would be very
>> interested in contributing in projects in this direction.
>>
>>
>> Best
>> Julian
>>
>>
>> [1] http://en.wikipedia.org/wiki/Sweave
>>
>>
>>
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Converting Org to Sweave (*.Rnw)
  2012-07-17 17:23   ` Julian Gehring
@ 2012-07-18  3:19     ` cberry
  0 siblings, 0 replies; 4+ messages in thread
From: cberry @ 2012-07-18  3:19 UTC (permalink / raw)
  To: emacs-orgmode

Julian Gehring <julian.gehring@gmail.com> writes:

> Hi Chuck,
>
> thanks, what you describe seems to me like a already quite elaborated
> solution.  I would be very interested in your existing implementation
> for this.
>
> As you mentioned, there will probably have to be a trade-off between
> the syntax/functionality of Org-mode/babel and Sweave.  But already a
> solution being able to handle to obvious cases of header argumnets
> would be step forward in bringing Org-mode even closer to R Sweave.
>

Julian,

Please take a look at https://github.com/chasberry/orgmode-accessories
and try it out.

ravel.org implements a couple of backends to export to Sweave and brew
style documents. There are commands embedded to create e-ravel.el, which
powers the backends as well as commentary on how to implement some
extensions.

There are two POC *.org files which show some of the possibilities.

Best,

Chuck


[snip]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-07-18  3:20 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-17 12:19 Converting Org to Sweave (*.Rnw) Julian Gehring
2012-07-17 16:05 ` cberry
2012-07-17 17:23   ` Julian Gehring
2012-07-18  3:19     ` cberry

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).