From mboxrd@z Thu Jan 1 00:00:00 1970 From: Rainer M Krug Subject: Using R in Org mode with several sourced files Date: Tue, 2 Feb 2010 15:35:55 +0200 Message-ID: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary=0016e6d645146bee83047e9e2e0a Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NcIvE-0005So-PW for emacs-orgmode@gnu.org; Tue, 02 Feb 2010 08:36:05 -0500 Received: from [199.232.76.173] (port=33181 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NcIvD-0005Rn-W6 for emacs-orgmode@gnu.org; Tue, 02 Feb 2010 08:36:04 -0500 Received: from Debian-exim by monty-python.gnu.org with spam-scanned (Exim 4.60) (envelope-from ) id 1NcIvA-0006QS-4b for emacs-orgmode@gnu.org; Tue, 02 Feb 2010 08:36:03 -0500 Received: from mail-ew0-f228.google.com ([209.85.219.228]:65174) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NcIv8-0006PU-RS for emacs-orgmode@gnu.org; Tue, 02 Feb 2010 08:35:59 -0500 Received: by ewy28 with SMTP id 28so59175ewy.8 for ; Tue, 02 Feb 2010 05:35:56 -0800 (PST) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org Cc: Dan Davison --0016e6d645146bee83047e9e2e0a Content-Type: multipart/alternative; boundary=0016e6d645146bee79047e9e2e08 --0016e6d645146bee79047e9e2e08 Content-Type: text/plain; charset=ISO-8859-1 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 Date: Mon, Feb 1, 2010 at 9:59 PM Subject: Re: Fwd: [ESS] generating TODO list? To: Rainer M Krug Cc: "Thomas S. Dye" [...] > 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 --0016e6d645146bee79047e9e2e08 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Hi

=A0Following 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 as= pect, which would be more difficult with my workflow. Let me explain. I am = writing fairly complex simulations, and I prefer to keep functions for diff= erent aspects of the simulation in different files. Therefore I have severa= l files, each one containing R code, which is sourced from a main file, whi= ch then sets the simulation up, which I then can start with calling simulat= eIt() in R. I could use .org files and tangle the code, but, as I am not th= at 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, i= f I had to tangle each file in addition to the saving (Ctrl-x s saves all f= iles - very useful for me!).=A0

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 lik= e the idea of having one HUGE file, with all the code, which then will be t= angled into several .R files.=A0
So I would like to have several .org files, where each one will be tan= gled 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, base= d 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 fil= eAll.org

These would then result in the files atta= ched, which then can be used from fileAll.R

Anothe= r 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 kno= w 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 TOD= O list?
To: Rainer M Krug <r.m.= krug@gmail.com>
Cc: "Thomas S. Dye" <tsd@tsdye.com>


[...]
> =A0 =A0 Sure, when you change the code in the org fi= le, you have to re-run
> =A0 =A0 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 havi= ng
> 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-a= ll with a
> tangle-all, or have the saving action automatically followed by a tang= ling (if
> it is an org file)?
>
>
> =A0 =A0 But that's just one possibility. Another would be simply t= o tangle all
> =A0 =A0 the blocks of R code to the same file. Then when you run that = file, you
> =A0 =A0 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.= =A0


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, the= n
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


>
>
>
> =A0 =A0 By the way, have you tried out the export facilities of org-mo= de? Have a
> =A0 =A0 look at the html export of the above org file [C-c C-e (org-ex= port)
> =A0 =A0 brings up the export options]. You can create links in the org= file to
> =A0 =A0 graphical output from R and these graphs will be included in t= he
> =A0 =A0 exported HTML/LaTeX.
>
>
> No - I just discovered the org-mode yesterday.
>
> Cheers,
>
> Rainer
> =A0
>
>
> =A0 =A0 Dan
>
> =A0 =A0 >
> =A0 =A0 > If that could be done, it would be a perfect example, how= one could use
> =A0 =A0 > org-babel in real R programming. The other option, would = be a "make file"
> =A0 =A0 > equivalent, which contains all the "tangle file ...&= quot; commands, and which
> =A0 =A0 could
> =A0 =A0 > be executed in the block above.
> =A0 =A0 > =A0
> =A0 =A0 >
> =A0 =A0 >
> =A0 =A0 > =A0 =A0 And it's also worth looking at the noweb-styl= e references for
> =A0 =A0 assembling
> =A0 =A0 >
> =A0 =A0 > =A0 =A0 different code blocks into a single code block. S= o with reference to
> =A0 =A0 the
> =A0 =A0 > =A0 =A0 distinction between "source is real" vs= . "R objects are real", from
> =A0 =A0 > =A0 =A0 the org-babel point of view the org-mode files ar= e real and contain
> =A0 =A0 the
> =A0 =A0 > =A0 =A0 source code along with essential project developm= ent and planning
> =A0 =A0 notes,
> =A0 =A0 > =A0 =A0 and the .R files are an ephemeral product of the = org-mode source.
> =A0 =A0 >
> =A0 =A0 >
> =A0 =A0 > As I said, it makes perfect sense, but the problem is the= additional step
> =A0 =A0 > needed. If this could be avoided (e.g. "make file&qu= ot;) I would very likely
> =A0 =A0 use the
> =A0 =A0 > org-mode.
> =A0 =A0 >
> =A0 =A0 > Thanks for your very helpful comments,
> =A0 =A0 >
> =A0 =A0 > Rainer
> =A0 =A0 >
> =A0 =A0 >
> =A0 =A0 >
> =A0 =A0 > =A0 =A0 Dan
> =A0 =A0 >
> =A0 =A0 > =A0 =A0 http://orgmode.org/worg/org-contrib/babel= /intro.php#
> =A0 =A0 literate-programming
> =A0 =A0 > =A0 =A0 http://orgmode.org/worg/org-contrib/b= abel/reference.php#
> =A0 =A0 > =A0 =A0 function-org-babel-tangle
> =A0 =A0 >
> =A0 =A0 >
> =A0 =A0 >
> =A0 =A0 >
> =A0 =A0 > =A0 =A0 >
> =A0 =A0 > =A0 =A0 > =A0 =A0 I will be looking into it anyway, be= cause it REALLY looks very
> =A0 =A0 > =A0 =A0 useful.
> =A0 =A0 > =A0 =A0 >
> =A0 =A0 > =A0 =A0 >
> =A0 =A0 > =A0 =A0 >
> =A0 =A0 > =A0 =A0 > =A0 =A0 =A0 =A0 You might want to join the O= rg-mode mailing list. =A0The
> =A0 =A0 authors of
> =A0 =A0 > =A0 =A0 > =A0 =A0 =A0 =A0 Org-babel, Dan Davison and E= ric Schulte, both respond to
> =A0 =A0 > =A0 =A0 questions
> =A0 =A0 > =A0 =A0 > =A0 =A0 =A0 =A0 there. =A0Also, there are se= veral Org-babel users there who
> =A0 =A0 are
> =A0 =A0 > =A0 =A0 much
> =A0 =A0 > =A0 =A0 > =A0 =A0 =A0 =A0 better than I am at figuring= out why things aren't working
> =A0 =A0 right.
> =A0 =A0 > =A0 =A0 >
> =A0 =A0 > =A0 =A0 > =A0 =A0 =A0 =A0 What happens when you try Ct= rl-C ' while in a code block?
> =A0 =A0 =A0If
> =A0 =A0 > =A0 =A0 Org-babel
> =A0 =A0 > =A0 =A0 > =A0 =A0 =A0 =A0 is initialized then this sho= uld take you to a new window
> =A0 =A0 with ESS
> =A0 =A0 > =A0 =A0 as
> =A0 =A0 > =A0 =A0 > =A0 =A0 =A0 =A0 the editing mode.
> =A0 =A0 > =A0 =A0 >
> =A0 =A0 > =A0 =A0 >
> =A0 =A0 > =A0 =A0 > =A0 =A0 Well - I used Ctrl-c ` instead of Ct= rl-c ' -- working now.
> =A0 =A0 > =A0 =A0 >
> =A0 =A0 > =A0 =A0 >
> =A0 =A0 > =A0 =A0 > =A0 =A0 Thanks a lot,
> =A0 =A0 > =A0 =A0 >
> =A0 =A0 > =A0 =A0 > =A0 =A0 Rainer
> =A0 =A0 > =A0 =A0 >
> =A0 =A0 > =A0 =A0 >
> =A0 =A0 > =A0 =A0 >
> =A0 =A0 > =A0 =A0 >
> =A0 =A0 > =A0 =A0 > =A0 =A0 =A0 =A0 All the best,
> =A0 =A0 > =A0 =A0 > =A0 =A0 =A0 =A0 Tom
> =A0 =A0 > =A0 =A0 >
> =A0 =A0 > =A0 =A0 >
> =A0 =A0 > =A0 =A0 >


-= -
NEW GERMAN FAX NUMBER!!!

Rainer M. Krug, PhD (Conservation Eco= logy, SUN), MSc (Conservation Biology, UCT), Dipl. Phys. (Germany)

C= entre of Excellence for Invasion Biology
Natural Sciences Building
Office Suite 2039
Stellenbosch UniversityMain Campus, Merriman Avenue
Stellenbosch
South Africa

Cell:= =A0 =A0 =A0 =A0 =A0 +27 - (0)83 9479 042
Fax: =A0 =A0 =A0 =A0 =A0 =A0+2= 7 - (0)86 516 2782
Fax: =A0 =A0 =A0 =A0 =A0 =A0+49 - (0)321 2125 2244
email: =A0 =A0 =A0 = =A0 =A0Rainer@krugs.de

Skype:= =A0 =A0 =A0 =A0 =A0RMkrug
Google: =A0 =A0 =A0 =A0 R.M.Krug@gmail.com

--0016e6d645146bee79047e9e2e08-- --0016e6d645146bee83047e9e2e0a Content-Type: application/octet-stream; name="file1.R" Content-Disposition: attachment; filename="file1.R" Content-Transfer-Encoding: base64 X-Attachment-Id: f_g56q5mvr0 bXVsdGlwbHkgPC0gZnVuY3Rpb24oeCx5KSB7CiAgcmV0dXJuKHggKiB5KQp9Cg== --0016e6d645146bee83047e9e2e0a Content-Type: application/octet-stream; name="file2.R" Content-Disposition: attachment; filename="file2.R" Content-Transfer-Encoding: base64 X-Attachment-Id: f_g56q5wl11 ZGl2aWRlIDwtIGZ1bmN0aW9uKHgseSkgewogIHJldHVybih4IC8geSkKfQo= --0016e6d645146bee83047e9e2e0a Content-Type: application/octet-stream; name="file3.R" Content-Disposition: attachment; filename="file3.R" Content-Transfer-Encoding: base64 X-Attachment-Id: f_g56q62hi2 YWRkIDwtIGZ1bmN0aW9uKHgseSkgewogIHJldHVybih4ICsgeSkKfQo= --0016e6d645146bee83047e9e2e0a Content-Type: application/octet-stream; name="fileAll.R" Content-Disposition: attachment; filename="fileAll.R" Content-Transfer-Encoding: base64 X-Attachment-Id: f_g56q99wn3 c291cmNlKCJmaWxlMS5SIikKc291cmNlKCJmaWxlMi5SIikKc291cmNlKCJmaWxlMy5SIikKCnNp bUFsbCA8LSBmdW5jdGlvbigpIHsKICBtdWx0aXBseSgKICAgICAgICAgICBydW5pZigxMCksCiAg ICAgICAgICAgYWRkKAogICAgICAgICAgICAgICAxMCwKICAgICAgICAgICAgICAgZGl2aWRlKDIw LCAxMCkKICAgICAgICAgICAgICAgKQogICAgICAgICAgICkKfQo= --0016e6d645146bee83047e9e2e0a Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ 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 --0016e6d645146bee83047e9e2e0a--