From: Rainer M Krug <r.m.krug@gmail.com>
To: emacs-orgmode@gnu.org
Cc: Dan Davison <davison@stats.ox.ac.uk>
Subject: Using R in Org mode with several sourced files
Date: Tue, 2 Feb 2010 15:35:55 +0200 [thread overview]
Message-ID: <fb7c7e871002020535y32bf7bcw4451a18f6dc75e04@mail.gmail.com> (raw)
[-- Attachment #1.1: Type: text/plain, Size: 7531 bytes --]
Hi
Following a discussion about how one could create a TODO list in ESS (see
below), Thomas Dye and Dan Davison suggested to look into org-mode and
org-babel and it looks really interesting. I just have one aspect, which
would be more difficult with my workflow. Let me explain. I am writing
fairly complex simulations, and I prefer to keep functions for different
aspects of the simulation in different files. Therefore I have several
files, each one containing R code, which is sourced from a main file, which
then sets the simulation up, which I then can start with calling
simulateIt() in R. I could use .org files and tangle the code, but, as I am
not that organised, I even forget sometimes to save before I source the file
and therefore still work with the old version - this would be more
difficult, if I had to tangle each file in addition to the saving (Ctrl-x s
saves all files - very useful for me!).
One option would be to combine all actual files into a single one, and then
tangle in different .R files, but I somehow do not like the idea of having
one HUGE file, with all the code, which then will be tangled into several .R
files.
So I would like to have several .org files, where each one will be tangled
into a separate .R file, which then will be sourced from a final main file.
As I understand org-mode, I could still have a single TODO list, based on
the agenda in org-mode.
So my question is, if this process could be automated. One idea was a kind
of a "make file", in which I specify:
tangle file1.org
tangle file2.org
tangle file3.org
tangle fileAll.org
These would then result in the files attached, which then can be used from
fileAll.R
Another idea was to have emacs automatically tangle the file after saving.
But I am sure there are also other possibilities.
I have to say, I am absolutely new to org-mode, and know nearly nothing
about lisp.
Cheers,
Rainer
---------- Forwarded message ----------
From: Dan Davison <davison@stats.ox.ac.uk>
Date: Mon, Feb 1, 2010 at 9:59 PM
Subject: Re: Fwd: [ESS] generating TODO list?
To: Rainer M Krug <r.m.krug@gmail.com>
Cc: "Thomas S. Dye" <tsd@tsdye.com>
[...]
> Sure, when you change the code in the org file, you have to re-run
> org-babel-tangle before you run your new R code.
>
>
> Ant this is the critical point: I can save all files which need to be
saved in
> ESS by Ctrl-x s (or was it Ctrl-x Ctrl-s ? I always do both). But having
> manually to go through all files, is something I am likely to forget. If I
> could tangle all files with one command, that wouls work (I have about 10
files
> for the project which are then sourced...). Could I combine the save-all
with a
> tangle-all, or have the saving action automatically followed by a tangling
(if
> it is an org file)?
>
>
> But that's just one possibility. Another would be simply to tangle all
> the blocks of R code to the same file. Then when you run that file,
you
> know that your function definitions will be up to date.
>
>
> It is quite strange, that there is no possibility to script emacs from org
mode
> like all the other languages? because that would be perfect for this.
I am certain that there is going to be a good solution for all your
concerns! I think you want to be thinking along the lines of maintaining
a _single_ org file for your project, and either including the code in
different subtrees of that file, or referring to external files from
within that file. But if the right solution doesn't doesn't already
exist, and it's a good idea, then someone will cook it up in
elisp. Could we move this discussion to the org-mode list? If you
describe what you want to do, with a toy example if that's helpful, then
I believe you will see that problems do not remain without solution for
very long on emacs-orgmode@gnu.org.
Meanwhile, have a look at this
http://doc.norang.ca/org-mode.html
to see some of what org-mode can do (the website itself is made in
org-mode of course).
Dan
>
>
>
> By the way, have you tried out the export facilities of org-mode? Have
a
> look at the html export of the above org file [C-c C-e (org-export)
> brings up the export options]. You can create links in the org file to
> graphical output from R and these graphs will be included in the
> exported HTML/LaTeX.
>
>
> No - I just discovered the org-mode yesterday.
>
> Cheers,
>
> Rainer
>
>
>
> Dan
>
> >
> > If that could be done, it would be a perfect example, how one could
use
> > org-babel in real R programming. The other option, would be a "make
file"
> > equivalent, which contains all the "tangle file ..." commands, and
which
> could
> > be executed in the block above.
> >
> >
> >
> > And it's also worth looking at the noweb-style references for
> assembling
> >
> > different code blocks into a single code block. So with
reference to
> the
> > distinction between "source is real" vs. "R objects are real",
from
> > the org-babel point of view the org-mode files are real and
contain
> the
> > source code along with essential project development and
planning
> notes,
> > and the .R files are an ephemeral product of the org-mode
source.
> >
> >
> > As I said, it makes perfect sense, but the problem is the additional
step
> > needed. If this could be avoided (e.g. "make file") I would very
likely
> use the
> > org-mode.
> >
> > Thanks for your very helpful comments,
> >
> > Rainer
> >
> >
> >
> > Dan
> >
> > http://orgmode.org/worg/org-contrib/babel/intro.php#
> literate-programming
> > http://orgmode.org/worg/org-contrib/babel/reference.php#
> > function-org-babel-tangle
> >
> >
> >
> >
> > >
> > > I will be looking into it anyway, because it REALLY looks
very
> > useful.
> > >
> > >
> > >
> > > You might want to join the Org-mode mailing list. The
> authors of
> > > Org-babel, Dan Davison and Eric Schulte, both respond
to
> > questions
> > > there. Also, there are several Org-babel users there
who
> are
> > much
> > > better than I am at figuring out why things aren't
working
> right.
> > >
> > > What happens when you try Ctrl-C ' while in a code
block?
> If
> > Org-babel
> > > is initialized then this should take you to a new
window
> with ESS
> > as
> > > the editing mode.
> > >
> > >
> > > Well - I used Ctrl-c ` instead of Ctrl-c ' -- working now.
> > >
> > >
> > > Thanks a lot,
> > >
> > > Rainer
> > >
> > >
> > >
> > >
> > > All the best,
> > > Tom
> > >
> > >
> > >
--
NEW GERMAN FAX NUMBER!!!
Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation Biology,
UCT), Dipl. Phys. (Germany)
Centre of Excellence for Invasion Biology
Natural Sciences Building
Office Suite 2039
Stellenbosch University
Main Campus, Merriman Avenue
Stellenbosch
South Africa
Cell: +27 - (0)83 9479 042
Fax: +27 - (0)86 516 2782
Fax: +49 - (0)321 2125 2244
email: Rainer@krugs.de
Skype: RMkrug
Google: R.M.Krug@gmail.com
[-- Attachment #1.2: Type: text/html, Size: 10229 bytes --]
[-- Attachment #2: file1.R --]
[-- Type: application/octet-stream, Size: 46 bytes --]
multiply <- function(x,y) {
return(x * y)
}
[-- Attachment #3: file2.R --]
[-- Type: application/octet-stream, Size: 44 bytes --]
divide <- function(x,y) {
return(x / y)
}
[-- Attachment #4: file3.R --]
[-- Type: application/octet-stream, Size: 41 bytes --]
add <- function(x,y) {
return(x + y)
}
[-- Attachment #5: fileAll.R --]
[-- Type: application/octet-stream, Size: 209 bytes --]
source("file1.R")
source("file2.R")
source("file3.R")
simAll <- function() {
multiply(
runif(10),
add(
10,
divide(20, 10)
)
)
}
[-- Attachment #6: Type: text/plain, Size: 201 bytes --]
_______________________________________________
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode
next reply other threads:[~2010-02-02 13:36 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-02-02 13:35 Rainer M Krug [this message]
2010-02-02 18:03 ` Using R in Org mode with several sourced files Thomas S. Dye
2010-02-02 18:26 ` Rainer M Krug
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=fb7c7e871002020535y32bf7bcw4451a18f6dc75e04@mail.gmail.com \
--to=r.m.krug@gmail.com \
--cc=davison@stats.ox.ac.uk \
--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 external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.