Re: [O] import R data frame into org-mode table

2013-07-30 Thread Cook, Malcolm

  Indeed, thanks, and, my worked out example follows using emacs 2.18.9 and 
  org-mode version 8.0.6
 
 
 2.18.9?

oops, that was the GTK_ Version number.  My emacs is 24.3.1.

 #+LATEX: \listoftables
  #+LaTeX_HEADER: \usepackage{longtable}
  #+name: longtabletest
  #+CAPTION: test of longtable caption
  #+begin_src R :results value :colnames yes
  data.frame(num=1:260,alpha=rep(LETTERS,10))
  #+end_src
 
  #+RESULTS:
  #+attr_latex: :environment longtable
  | num | alpha |
  |-+---|
  |   1 | A |
  |   2 | B |
  ...
 
 Does this really produce a table caption for you when you export to
 latex?
 And does the attr_latex line stay there at the top of the table
 when the code block is evaluated?  

Yes and Yes.  At least, I swear it worked in my hands yesterday, but today the 
answer is No and No.  !!  I can't explain what has changed.

 For me, the answers are no and
 no. 
 I have to rewrite it as follows in order for it to work:
 
  #+begin_src R :results value :colnames yes
  data.frame(num=1:260,alpha=rep(LETTERS,10))
  #+end_src
 
  #+CAPTION: test of longtable caption
  #+attr_latex: :environment longtable
  #+RESULTS:
  | num | alpha |
  |-+---|
  |   1 | A |
  |   2 | B |

In my hands, both the #+CAPTION and the #+att_latex as you place them are 
deleted upon source block evaluation. 

Are you sure your placement works for you?

Summary: In my hands today, there is no placement of them that both survives 
source block re-evaluation and works.  And, they can both be placed immediately 
above or below the #+RESULTS: line and are respected on export.

(However, another funny interaction, the caption of the longtable has multiple 
entries, one for each page, in my #+LATEX: \listoftables )

H

 
 --
 Nick
 
 




Re: [O] import R data frame into org-mode table

2013-07-29 Thread Rob Stewart
Hi Andreas,

On 17 July 2013 23:09, Andreas Leha andreas.l...@med.uni-goettingen.de wrote:

 Definitely there is:

 --8---cut here---start-8---
 #+begin_src R :results table :colnames yes
   read.csv('test.csv')
 #+end_src

 #+results:
 | X | Variant | Xaxis | N |   mean |   sd |   se |
 |---+-+---+---++--+--|
 | 1 | line1   |10 | 5 | 111.11 | 9.33 | 3.11 |
 | 1 | line1   |20 | 5 | 112.11 | 9.13 | 3.14 |
 | 1 | line1   |30 | 5 | 113.11 | 9.43 |  3.1 |
 | 1 | line2   |10 | 5 | 101.11 | 8.33 | 2.11 |
 | 1 | line2   |20 | 5 | 100.11 | 8.13 | 2.12 |
 | 1 | line2   |30 | 5 | 108.11 | 8.03 |  2.1 |

 --8---cut here---end---8---

Great. I've gone ahead and done this. There are two additional requirements:
1) My table needs a caption. Will #+CAPTION: just above the
#+BEGIN_SRC just work? Even better, a label, allowing me to also cross
reference it.
2) My table is too long for 1 page. It spans multiple pages
vertically. According to this StackOverflow answer
http://stackoverflow.com/a/2896850/1526266 , I should instead use
longtable, not tabular. Is there a way to coerce your above snippet to
use longtable, instead of tabular which is the default.

Thanks!

--
Rob



Re: [O] import R data frame into org-mode table

2013-07-29 Thread Cook, Malcolm
Hi Andreas,
 
 On 17 July 2013 23:09, Andreas Leha andreas.l...@med.uni-goettingen.de 
 wrote:
 
  Definitely there is:
 
  --8---cut here---start-8---
  #+begin_src R :results table :colnames yes
read.csv('test.csv')
  #+end_src
 
  #+results:
  | X | Variant | Xaxis | N |   mean |   sd |   se |
  |---+-+---+---++--+--|
  | 1 | line1   |10 | 5 | 111.11 | 9.33 | 3.11 |
  | 1 | line1   |20 | 5 | 112.11 | 9.13 | 3.14 |
  | 1 | line1   |30 | 5 | 113.11 | 9.43 |  3.1 |
  | 1 | line2   |10 | 5 | 101.11 | 8.33 | 2.11 |
  | 1 | line2   |20 | 5 | 100.11 | 8.13 | 2.12 |
  | 1 | line2   |30 | 5 | 108.11 | 8.03 |  2.1 |
 
  --8---cut here---end---8---
 
 Great. I've gone ahead and done this. There are two additional requirements:
 1) My table needs a caption. Will #+CAPTION: just above the
 #+BEGIN_SRC just work? 

Yes

 Even better, a label, allowing me to also cross
 reference it.
 2) My table is too long for 1 page. It spans multiple pages
 vertically. According to this StackOverflow answer
 http://stackoverflow.com/a/2896850/1526266 , I should instead use
 longtable, not tabular. Is there a way to coerce your above snippet to
 use longtable, instead of tabular which is the default.
 

Looks like your answer is here: 
http://orgmode.org/manual/Tables-in-LaTeX-export.html

 Thanks!
 
 --
 Rob




Re: [O] import R data frame into org-mode table

2013-07-29 Thread John Hendy
On Mon, Jul 29, 2013 at 10:35 AM, Cook, Malcolm m...@stowers.org wrote:
Hi Andreas,
  
  On 17 July 2013 23:09, Andreas Leha andreas.l...@med.uni-goettingen.de 
 wrote:
  
   Definitely there is:
  
   --8---cut here---start-8---
   #+begin_src R :results table :colnames yes
 read.csv('test.csv')
   #+end_src
  
   #+results:
   | X | Variant | Xaxis | N |   mean |   sd |   se |
   |---+-+---+---++--+--|
   | 1 | line1   |10 | 5 | 111.11 | 9.33 | 3.11 |
   | 1 | line1   |20 | 5 | 112.11 | 9.13 | 3.14 |
   | 1 | line1   |30 | 5 | 113.11 | 9.43 |  3.1 |
   | 1 | line2   |10 | 5 | 101.11 | 8.33 | 2.11 |
   | 1 | line2   |20 | 5 | 100.11 | 8.13 | 2.12 |
   | 1 | line2   |30 | 5 | 108.11 | 8.03 |  2.1 |
  
   --8---cut here---end---8---
  
  Great. I've gone ahead and done this. There are two additional requirements:
  1) My table needs a caption. Will #+CAPTION: just above the
  #+BEGIN_SRC just work?

 Yes

 Even better, a label, allowing me to also cross
  reference it.
  2) My table is too long for 1 page. It spans multiple pages
  vertically. According to this StackOverflow answer
  http://stackoverflow.com/a/2896850/1526266 , I should instead use
  longtable, not tabular. Is there a way to coerce your above snippet to
  use longtable, instead of tabular which is the default.
  

 Looks like your answer is here: 
 http://orgmode.org/manual/Tables-in-LaTeX-export.html

Sort of. Depends on the Org-mode version, and someone will have to
chime in on the updated status of various parts of the manual. For 8+,
I believe the syntax is different:

#+attr_latex: :environment longtable

Also, there have been many threads in the past about how to add
#+attr_latex lines to results output (mostly graphics/files)
successfully. If you simply take the above and add =#+attr_latex:
stuff= above the =#+results= line, babel won't recognize it and will
just create a new results block. If those on this email are already
well aware of this... my apologies for being redundant, but it causes
enough confusion that I figured I'd leave another bread crumb trail :)
Here's an example of a time that came up on the list:
- http://lists.gnu.org/archive/html/emacs-orgmode/2012-07/msg00237.html

You need to use any attributes (that includes #+begin/end_center, and
any #+attr_backend lines) *in combination with* a named source block.
So the full solution should look something like this:

#+name: export-table
#+begin_src R :results table :colnames yes
read.csv('test.csv')
#+end_src

#+RESULTS: export-table
#+attr_latex: :environment longtable
| | |

I see above that =:results output org= was used. There was some
discussion about this for use with the new exporter as I wasn't
getting great results:
- https://lists.gnu.org/archive/html/emacs-orgmode/2013-03/msg01582.html
- http://www.mail-archive.com/emacs-orgmode@gnu.org/msg69748.html

If it's working for you, don't worry about it. If not, you may find
some help in those threads. I've taken to using the ascii package for
output org-mode tables from R.
- http://orgmode.org/worg/org-contrib/babel/examples/ascii.html

Works great for me.


Good luck!
John



  Thanks!
  
  --
  Rob





Re: [O] import R data frame into org-mode table

2013-07-29 Thread Nick Dokos
John Hendy jw.he...@gmail.com writes:

 On Mon, Jul 29, 2013 at 10:35 AM, Cook, Malcolm m...@stowers.org wrote:
Hi Andreas,
  
  On 17 July 2013 23:09, Andreas Leha andreas.l...@med.uni-goettingen.de 
 wrote:
  
   Definitely there is:
  
   --8---cut here---start-8---
   #+begin_src R :results table :colnames yes
 read.csv('test.csv')
   #+end_src
  
   #+results:
   | X | Variant | Xaxis | N |   mean |   sd |   se |
   |---+-+---+---++--+--|
   | 1 | line1   |10 | 5 | 111.11 | 9.33 | 3.11 |
   | 1 | line1   |20 | 5 | 112.11 | 9.13 | 3.14 |
   | 1 | line1   |30 | 5 | 113.11 | 9.43 |  3.1 |
   | 1 | line2   |10 | 5 | 101.11 | 8.33 | 2.11 |
   | 1 | line2   |20 | 5 | 100.11 | 8.13 | 2.12 |
   | 1 | line2   |30 | 5 | 108.11 | 8.03 |  2.1 |
  
   --8---cut here---end---8---
  
  Great. I've gone ahead and done this. There are two additional 
 requirements:
  1) My table needs a caption. Will #+CAPTION: just above the
  #+BEGIN_SRC just work?

 Yes

I don't think so: the caption is a property of the table, not of the
code block, so putting it before the code block does not work (at least
in my limited 8.x tests). You have to put it before the table - see
example below.


 Even better, a label, allowing me to also cross
  reference it.
  2) My table is too long for 1 page. It spans multiple pages
  vertically. According to this StackOverflow answer
  http://stackoverflow.com/a/2896850/1526266 , I should instead use
  longtable, not tabular. Is there a way to coerce your above snippet to
  use longtable, instead of tabular which is the default.
  

 Looks like your answer is here: 
 http://orgmode.org/manual/Tables-in-LaTeX-export.html

 Sort of. Depends on the Org-mode version, and someone will have to
 chime in on the updated status of various parts of the manual. For 8+,
 I believe the syntax is different:

 #+attr_latex: :environment longtable

 Also, there have been many threads in the past about how to add
 #+attr_latex lines to results output (mostly graphics/files)
 successfully. If you simply take the above and add =#+attr_latex:
 stuff= above the =#+results= line, babel won't recognize it and will
 just create a new results block. If those on this email are already
 well aware of this... my apologies for being redundant, but it causes
 enough confusion that I figured I'd leave another bread crumb trail :)
 Here's an example of a time that came up on the list:
 - http://lists.gnu.org/archive/html/emacs-orgmode/2012-07/msg00237.html


This is no longer the case: Eric S. fixed this a couple of months ago,
so that even an unlabeled #+RESULTS block will get the recomputed
results without creating a new block. The following exports fine to
latex/pdf with current org:

--8---cut here---start-8---

* foo

#+begin_src R :results table :colnames yes :exports results
  read.csv('test.csv')
#+end_src

#+NAME: foo
#+CAPTION: My table
#+ATTR_LATEX: :environment longtable
#+RESULTS:
| X | Variant | Xaxis | N |   mean |   sd |   se |
|---+-+---+---++--+--|
| 1 | line1   |10 | 5 | 111.11 | 9.33 | 3.11 |
| 1 | line1   |20 | 5 | 112.11 | 9.13 | 3.14 |
| 1 | line1   |30 | 5 | 113.11 | 9.43 |  3.1 |
| 1 | line2   |10 | 5 | 101.11 | 8.33 | 2.11 |
| 1 | line2   |20 | 5 | 100.11 | 8.13 | 2.12 |
| 1 | line2   |30 | 5 | 108.11 | 8.03 |  2.1 |


* bar

See Table \ref{foo}.
--8---cut here---end---8---

even satisfying the OP's desire for labeling the table so that the xref
will work (although there may be better methods to xref: I haven't kept
up with the recent discussions on the ML).

Of course, naming the code block should still be considered best
practice IMO.

-- 
Nick




Re: [O] import R data frame into org-mode table

2013-07-29 Thread Cook, Malcolm
-Original Message-
 From: John Hendy [mailto:jw.he...@gmail.com]
 Sent: Monday, July 29, 2013 11:03 AM
 To: Cook, Malcolm
 Cc: Rob Stewart; Andreas Leha; emacs-orgmode@gnu.org
 Subject: Re: [O] import R data frame into org-mode table
 
 On Mon, Jul 29, 2013 at 10:35 AM, Cook, Malcolm m...@stowers.org wrote:
 Hi Andreas,
   
   On 17 July 2013 23:09, Andreas Leha andreas.l...@med.uni-goettingen.de 
  wrote:
   
Definitely there is:
   
--8---cut here---start-8---
#+begin_src R :results table :colnames yes
  read.csv('test.csv')
#+end_src
   
#+results:
| X | Variant | Xaxis | N |   mean |   sd |   se |
|---+-+---+---++--+--|
| 1 | line1   |10 | 5 | 111.11 | 9.33 | 3.11 |
| 1 | line1   |20 | 5 | 112.11 | 9.13 | 3.14 |
| 1 | line1   |30 | 5 | 113.11 | 9.43 |  3.1 |
| 1 | line2   |10 | 5 | 101.11 | 8.33 | 2.11 |
| 1 | line2   |20 | 5 | 100.11 | 8.13 | 2.12 |
| 1 | line2   |30 | 5 | 108.11 | 8.03 |  2.1 |
   
--8---cut here---end---8---
   
   Great. I've gone ahead and done this. There are two additional 
  requirements:
   1) My table needs a caption. Will #+CAPTION: just above the
   #+BEGIN_SRC just work?
 
  Yes
 
  Even better, a label, allowing me to also cross
   reference it.
   2) My table is too long for 1 page. It spans multiple pages
   vertically. According to this StackOverflow answer
   http://stackoverflow.com/a/2896850/1526266 , I should instead use
   longtable, not tabular. Is there a way to coerce your above snippet to
   use longtable, instead of tabular which is the default.
   
 
  Looks like your answer is here: 
  http://orgmode.org/manual/Tables-in-LaTeX-export.html
 
 Sort of. Depends on the Org-mode version, and someone will have to
 chime in on the updated status of various parts of the manual. For 8+,
 I believe the syntax is different:
 
 #+attr_latex: :environment longtable
 
 Also, there have been many threads in the past about how to add
 #+attr_latex lines to results output (mostly graphics/files)
 successfully. If you simply take the above and add =#+attr_latex:
 stuff= above the =#+results= line, babel won't recognize it and will
 just create a new results block. If those on this email are already
 well aware of this... my apologies for being redundant, but it causes
 enough confusion that I figured I'd leave another bread crumb trail :)
 Here's an example of a time that came up on the list:
 - http://lists.gnu.org/archive/html/emacs-orgmode/2012-07/msg00237.html
 
 You need to use any attributes (that includes #+begin/end_center, and
 any #+attr_backend lines) *in combination with* a named source block.
 So the full solution should look something like this:
 
 #+name: export-table
 #+begin_src R :results table :colnames yes
 read.csv('test.csv')
 #+end_src
 
 #+RESULTS: export-table
 #+attr_latex: :environment longtable
 | | |
[Cook, Malcolm] 

Indeed, thanks, and, my worked out example follows using emacs 2.18.9 and 
org-mode version 8.0.6

#+LATEX: \listoftables  

 
#+LaTeX_HEADER: \usepackage{longtable}  

 
#+name: longtabletest   

 
#+CAPTION: test of longtable caption

 
#+begin_src R :results value :colnames yes  

 
data.frame(num=1:260,alpha=rep(LETTERS,10)) 

 
#+end_src

Re: [O] import R data frame into org-mode table

2013-07-29 Thread Nick Dokos
Cook, Malcolm m...@stowers.org writes:


 Indeed, thanks, and, my worked out example follows using emacs 2.18.9 and 
 org-mode version 8.0.6


2.18.9?

 #+LATEX: \listoftables
 #+LaTeX_HEADER: \usepackage{longtable}
 #+name: longtabletest
 #+CAPTION: test of longtable caption
 #+begin_src R :results value :colnames yes
 data.frame(num=1:260,alpha=rep(LETTERS,10))
 #+end_src

 #+RESULTS:
 #+attr_latex: :environment longtable
 | num | alpha |
 |-+---|
 |   1 | A |
 |   2 | B |   
 ...

Does this really produce a table caption for you when you export to
latex? And does the attr_latex line stay there at the top of the table
when the code block is evaluated?  For me, the answers are no and
no. I have to rewrite it as follows in order for it to work:

 #+begin_src R :results value :colnames yes
 data.frame(num=1:260,alpha=rep(LETTERS,10))
 #+end_src

 #+CAPTION: test of longtable caption
 #+attr_latex: :environment longtable
 #+RESULTS:
 | num | alpha |
 |-+---|
 |   1 | A |
 |   2 | B |

-- 
Nick





Re: [O] import R data frame into org-mode table

2013-07-17 Thread Andreas Leha
Rob Stewart robstewar...@gmail.com writes:

 I have an R script that generates a data frame, that I export to a CSV
 file. The data looks something like this:

 ,Variant,Xaxis,N,mean,sd,se
 1,line1,10,5,111.11,9.33,3.11
 1,line1,20,5,112.11,9.13,3.14
 1,line1,30,5,113.11,9.43,3.10
 1,line2,10,5,101.11,8.33,2.11
 1,line2,20,5,100.11,8.13,2.12
 1,line2,30,5,108.11,8.03,2.10

 I have an ongoing org-mode document in which I'd like to report this
 data. I'd like to add a table that looks something like this:

 | Variant | X Axis | Y Axis | N | Mean | Standard Deviation |
 Standard Error |
 
 ||

 The data will change frequently over the coming months. I'd like
 org-mode to auto-magically read a CSV file, to construct my org-table
 on-the-fly. I'd hoping to avoid copying and pasting results each time.

 Is there some org-mode or emacs+ESS magic I can use to populate my
 empty table, with source data from my CSV file?

 --
 Rob

Definitely there is:

--8---cut here---start-8---
#+begin_src R :results table :colnames yes
  read.csv('test.csv')
#+end_src

#+results:
| X | Variant | Xaxis | N |   mean |   sd |   se |
|---+-+---+---++--+--|
| 1 | line1   |10 | 5 | 111.11 | 9.33 | 3.11 |
| 1 | line1   |20 | 5 | 112.11 | 9.13 | 3.14 |
| 1 | line1   |30 | 5 | 113.11 | 9.43 |  3.1 |
| 1 | line2   |10 | 5 | 101.11 | 8.33 | 2.11 |
| 1 | line2   |20 | 5 | 100.11 | 8.13 | 2.12 |
| 1 | line2   |30 | 5 | 108.11 | 8.03 |  2.1 |

--8---cut here---end---8---

Regards,
Andreas




Re: [O] import R data frame into org-mode table

2013-07-17 Thread Thomas S. Dye
Rob Stewart robstewar...@gmail.com writes:

 I have an R script that generates a data frame, that I export to a CSV
 file. The data looks something like this:

 ,Variant,Xaxis,N,mean,sd,se
 1,line1,10,5,111.11,9.33,3.11
 1,line1,20,5,112.11,9.13,3.14
 1,line1,30,5,113.11,9.43,3.10
 1,line2,10,5,101.11,8.33,2.11
 1,line2,20,5,100.11,8.13,2.12
 1,line2,30,5,108.11,8.03,2.10

 I have an ongoing org-mode document in which I'd like to report this
 data. I'd like to add a table that looks something like this:

 | Variant | X Axis | Y Axis | N | Mean | Standard Deviation |
 Standard Error |
 
 ||

 The data will change frequently over the coming months. I'd like
 org-mode to auto-magically read a CSV file, to construct my org-table
 on-the-fly. I'd hoping to avoid copying and pasting results each time.

 Is there some org-mode or emacs+ESS magic I can use to populate my
 empty table, with source data from my CSV file?

 --
 Rob

Hi Rob,

Andreas' post answers your specific question.

In your situation, I typically don't run through a csv file, but just
write the R script so the data frame is returned to the Org mode buffer
as the result of the source code block.

As for the translation of column heads, see the ascii package for R,
which has a print() routine that recognizes Org mode as a type of
output, and which has facilities for formatting column names.

Here is an example from some work in progress that uses a session:

#+property: exports results
#+property: colnames yes
#+property: session *adzes*

#+name: lda-mid-z
#+header: :results output org
#+begin_src R 
  y - edxrf[edxrf$lab=='UH-Hilo',]
  fit - lda(as.factor(site) ~  rb_ppm + sr_ppm + y_ppm + zr_ppm + nb_ppm,
 data=y, na.action=na.omit, CV=TRUE)
  adzes - y$site=='unknown'
  cap - Assignment of unknowns to sources
  z - 
ascii(cbind(BPBM=y$bpbm[adzes],round(fit$posterior[adzes,],2)),header=T,include.colnames=T,caption=cap)
  print(z,type=org)
  rm(y,fit,adzes,cap,z)
#+end_src

#+RESULTS: lda-mid-z
#+BEGIN_ORG
#+CAPTION: Assignment of unknowns to sources
| BPBM  | Haleakala | Kilauea | Mauna Kea | Nu`u | Pololu | 
Waiahole | unknown |
|---+---+-+---+--++--+-|
| 1985.134.01 adze  | 0 | 0.1 | 0 | 0| 0  | 
0.64 | 0.27|
| 50-HA-1349-G-5 adze   | 0 | 0.85| 0 | 0| 0  | 
0| 0.14|
| 50-HA-900-P24-1 microadze | 0 | 0   | 1 | 0| 0  | 
0| 0   |

...

hth,
Tom


-- 
Thomas S. Dye
http://www.tsdye.com



[O] import R data frame into org-mode table

2013-07-16 Thread Rob Stewart
I have an R script that generates a data frame, that I export to a CSV
file. The data looks something like this:

,Variant,Xaxis,N,mean,sd,se
1,line1,10,5,111.11,9.33,3.11
1,line1,20,5,112.11,9.13,3.14
1,line1,30,5,113.11,9.43,3.10
1,line2,10,5,101.11,8.33,2.11
1,line2,20,5,100.11,8.13,2.12
1,line2,30,5,108.11,8.03,2.10

I have an ongoing org-mode document in which I'd like to report this
data. I'd like to add a table that looks something like this:

| Variant | X Axis | Y Axis | N | Mean | Standard Deviation |
Standard Error |

||

The data will change frequently over the coming months. I'd like
org-mode to auto-magically read a CSV file, to construct my org-table
on-the-fly. I'd hoping to avoid copying and pasting results each time.

Is there some org-mode or emacs+ESS magic I can use to populate my
empty table, with source data from my CSV file?

--
Rob