emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Austin Frank <austin.frank@gmail.com>
To: emacs-orgmode@gnu.org
Subject: Re: Org-mode and ESS
Date: Wed, 12 Nov 2008 14:42:24 -0500	[thread overview]
Message-ID: <m0d4h0loin.fsf@gmail.com> (raw)
In-Reply-To: 2c75873c0811111000m3c80e8e4rf08b742e80300cd0@mail.gmail.com


[-- Attachment #1.1: Type: text/plain, Size: 3300 bytes --]

On Tue, Nov 11 2008, Graham Smith wrote:

> Is any one using Org-mode with ESS.  ESS seems to need a file with a
> *.R name to work, but it would be really useful to use Org-mode
> features to keep notes of comments and code, before sending to R, and
> of course to copy results back into an Org-Mode file from R.
>
> As a search here and a google hasn't thrown up anything obvious, I
> assume not, but I thought I would ask.

In my local git repo of the org sources I have a pretty nice setup for
using R or S inside org-mode.  I liked the in-file native editing of
source code so much that I decided that I wanted to use org files as
source files with Sweave (instead of using .Rtex or .Rnw files).  My
goal was to export documents with embedded R code, rather than to use
org within the comments of R files.  I can certainly see a use for the
latter approach (which seems to be what you have in mind), as well.

There was recently a thread where someone created a preprocessing system
for specific types of blocks.  That would be another possible strategy
for evaluating blocks of R code before export.  Since that facility
didn't exist yet and there was already the extensible Sweave
pre-processor, I took the route of making Sweave org-aware.


Basically, in the workflow I've developed, I create a file with the
extension .Rorg, say homework_key.Rorg.  Within that file, I can embed
blocks of R code, and can refer to variables defined in the R code
contained in the document.

--8<---------------cut here---------------start------------->8---
#+BEGIN_R
a <- 3
a
#+END_R

* the value of a is \R{a}
* the value of a + 3 is \R{a + 3}  
--8<---------------cut here---------------end--------------->8---

Executing C-c ' inside the block takes you into a temporary buffer
that's in ESS mode, with full support for interactive evaluation.


When I'm ready to export, I run the R command

  Sweave("homework_key.Rorg", driver=RweaveOrgLatex, syntax=SweaveSyntaxOrg).

(I've defined those driver and syntax functions locally).  This creates
a new file, homework_key.org.  In the new file, the above text would be
translated into

--8<---------------cut here---------------start------------->8---
#+BEGIN_LATEX
\begin{Schunk}
\begin{Sinput}
> a <- 3
> a
\end{Sinput}
\begin{Soutput}
[1] 3
\end{Soutput}
\end{Schunk}
#+END_LATEX

* the value of a is 3
* the value of a + 3 is 6
--8<---------------cut here---------------end--------------->8---

The plain homework_key.org file could then be exported into \LaTeX.  It
even works with the new pdf export.
  

I haven't put the code anywhere public because there are several things
I still need to do:

- test graphic creation and export
- improve generation of latex headers
- automate processing from .Rorg to .tex (or .pdf) (currently at least 3
  steps, should be 1)
- come up with suggested keybindings for inserting the #+BEGIN/END_R
  blocks
- create a driver to generate HTML instead of \LaTeX

Still, it is in a works-for-me state at the moment, and I could send a
pull request to Carsten or could push it worg if folks were interested.

Let me know,
/au


-- 
Austin Frank
http://aufrank.net
GPG Public Key (D7398C2F): http://aufrank.net/personal.asc

[-- Attachment #1.2: Type: application/pgp-signature, Size: 193 bytes --]

[-- Attachment #2: Type: text/plain, Size: 204 bytes --]

_______________________________________________
Emacs-orgmode mailing list
Remember: use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode

  parent reply	other threads:[~2008-11-12 19:42 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-11-11 18:00 Org-mode and ESS Graham Smith
2008-11-11 18:30 ` Detlef Steuer
2008-11-11 19:13   ` Graham Smith
2008-11-12 19:42 ` Austin Frank [this message]
2008-11-12 19:51   ` Graham Smith
2008-11-12 20:45   ` Detlef Steuer
2008-11-13  3:22   ` Eric Schulte
2008-11-13  5:40     ` Austin Frank
2008-11-14  1:22       ` Eric Schulte
2008-11-16  1:50         ` Eric Schulte

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m0d4h0loin.fsf@gmail.com \
    --to=austin.frank@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).