emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [babel] R - variable names in summary
@ 2009-12-08 23:50 Graham Smith
  2009-12-09  4:38 ` Austin Frank
  2009-12-09 16:38 ` Dan Davison
  0 siblings, 2 replies; 14+ messages in thread
From: Graham Smith @ 2009-12-08 23:50 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 1526 bytes --]

Dan

I have started a new thread so it has a propel babel string. I have
also created a small file for testing.

The colnames t works as expected, but how do I then see the variable
names when using the summary command, and str doesn't work at all
(source block produced no output) . They appear OK in the R buffer.

Orgmode+babel output below

Graham

#+srcname:babeltest
#+begin_src R :colnames t
babeltest<-read.csv("/home/graham/Dropbox/myotis/Learn/learn/babeltest.csv",header=TRUE)
#+end_src

#+resname: babeltest
| "ID" | "var1" | "var2" | "var3" |
|------+--------+--------+--------|
|    1 |     34 |      1 |    400 |
|    2 |     56 |      4 |    499 |
|    3 |     78 |      3 |    500 |
|    4 |     34 |      5 |    600 |
|    5 |     56 |      6 |    500 |
|    6 |     23 |      7 |    300 |
|    7 |     45 |      5 |    200 |
|    8 |     23 |      6 |    340 |
|    9 |     89 |      7 |    400 |
|   10 |     46 |      4 |    450 |



#+begin_src R :session babeltest
summary(babeltest)
#+end_src

#+resname:
| "Min.   : 1.00" | "Min.   :23.0" | "Min.   :1.0" | "Min.   :200.0" |
| "1st Qu.: 3.25" | "1st Qu.:34.0" | "1st Qu.:4.0" | "1st Qu.:355.0" |
| "Median : 5.50" | "Median :45.5" | "Median :5.0" | "Median :425.0" |
| "Mean   : 5.50" | "Mean   :48.4" | "Mean   :4.8" | "Mean   :418.9" |
| "3rd Qu.: 7.75" | "3rd Qu.:56.0" | "3rd Qu.:6.0" | "3rd Qu.:499.8" |
| "Max.   :10.00" | "Max.   :89.0" | "Max.   :7.0" | "Max.   :600.0" |

#+begin_src R :session babeltest
str(babeltest)
#+end_src

#+resname:

[-- Attachment #2: babeltest.csv --]
[-- Type: text/csv, Size: 129 bytes --]

ID,var1,var2,var3
1,34,1,400
2,56,4,499
3,78,3,500
4,34,5,600
5,56,6,500
6,23,7,300
7,45,5,200
8,23,6,340
9,89,7,400
10,46,4,450

[-- Attachment #3: 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

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

* Re: [babel] R - variable names in summary
  2009-12-08 23:50 [babel] R - variable names in summary Graham Smith
@ 2009-12-09  4:38 ` Austin Frank
  2009-12-09 16:46   ` Graham Smith
  2009-12-09 16:38 ` Dan Davison
  1 sibling, 1 reply; 14+ messages in thread
From: Austin Frank @ 2009-12-09  4:38 UTC (permalink / raw)
  To: emacs-orgmode


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

On Tue, Dec 08 2009, Graham Smith wrote:

> The colnames t works as expected, but how do I then see the variable
> names when using the summary command, and str doesn't work at all
> (source block produced no output) . They appear OK in the R buffer.

This is help from the R side, not from the org-babel side.  If these
suggestions don't work, one of the babelers will have to step in.

Many functions that print output to the interactive buffer will not
produce that output when called outside of the interactive buffer.  For
these functions, if you wrap them in print() you can usually get the
results you want.  So, in your R code blocks, try

  print(summary(whatever))

and

  print(str(whatever))

If all you need is the names of the columns,

  print(names(whatever))

might be useful.

HTH,
/au

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

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

[-- Attachment #2: 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

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

* Re: [babel] R - variable names in summary
  2009-12-08 23:50 [babel] R - variable names in summary Graham Smith
  2009-12-09  4:38 ` Austin Frank
@ 2009-12-09 16:38 ` Dan Davison
  2009-12-09 17:05   ` Graham Smith
  1 sibling, 1 reply; 14+ messages in thread
From: Dan Davison @ 2009-12-09 16:38 UTC (permalink / raw)
  To: Graham Smith; +Cc: emacs-orgmode

Graham Smith <myotisone@gmail.com> writes:

> Dan
>
> I have started a new thread so it has a propel babel string. I have
> also created a small file for testing.
>

Hi Graham,

> The colnames t works as expected, but how do I then see the variable
> names when using the summary command,

Just use :colnames t again for that.

>  and str doesn't work at all
> (source block produced no output) . They appear OK in the R buffer. 

OK, so Austin was right about the problem here. Remember that by
default, org-babel works in ':results value' mode -- i.e., it tries to
give you back an org table corresponding to the *value* of the last
expression in your code. But the R function str() simply *prints* out
some information about the object. You can see that it has no useful
value by doing this in the R buffer:

> str.value <- str(babeltest)
'data.frame':	10 obs. of  4 variables:
 $ ID  : int  1 2 3 4 5 6 7 8 9 10
 $ var1: int  34 56 78 34 56 23 45 23 89 46
 $ var2: int  1 4 3 5 6 7 5 6 7 4
 $ var3: int  400 499 500 600 500 300 200 340 400 450
> str.value
NULL

What you need here is ':results output', which tells org-babel to give
you back whatever printed output there is. You'll need to use :results
output whenever you want to see the printed output from R as opposed to
the value of a data frame/table/vector etc.

I've pasted a working version of your example below.

Dan

>
> Orgmode+babel output below
>
> Graham
>
> #+srcname:babeltest
> #+begin_src R :colnames t

(This needs ':session babeltest' for your example to work, but I expect
that just accidentally got left out of your email)

> babeltest<-read.csv("/home/graham/Dropbox/myotis/Learn/learn/babeltest.csv",header=TRUE)
> #+end_src

-------------------------------------------------------------------------------
#+srcname:babeltest
#+begin_src R :colnames t :session babeltest
babeltest<-read.csv("/tmp/babeltest.csv",header=TRUE)
#+end_src

#+results: babeltest
| "ID" | "var1" | "var2" | "var3" |
|------+--------+--------+--------|
|    1 |     34 |      1 |    400 |
|    2 |     56 |      4 |    499 |
|    3 |     78 |      3 |    500 |
|    4 |     34 |      5 |    600 |
|    5 |     56 |      6 |    500 |
|    6 |     23 |      7 |    300 |
|    7 |     45 |      5 |    200 |
|    8 |     23 |      6 |    340 |
|    9 |     89 |      7 |    400 |
|   10 |     46 |      4 |    450 |

#+begin_src R :session babeltest :colnames t
summary(babeltest)
#+end_src

#+results:
| "ID"            | "var1"         | "var2"        | "var3"          |
|-----------------+----------------+---------------+-----------------|
| "Min.   : 1.00" | "Min.   :23.0" | "Min.   :1.0" | "Min.   :200.0" |
| "1st Qu.: 3.25" | "1st Qu.:34.0" | "1st Qu.:4.0" | "1st Qu.:355.0" |
| "Median : 5.50" | "Median :45.5" | "Median :5.0" | "Median :425.0" |
| "Mean   : 5.50" | "Mean   :48.4" | "Mean   :4.8" | "Mean   :418.9" |
| "3rd Qu.: 7.75" | "3rd Qu.:56.0" | "3rd Qu.:6.0" | "3rd Qu.:499.8" |
| "Max.   :10.00" | "Max.   :89.0" | "Max.   :7.0" | "Max.   :600.0" |

#+begin_src R :session babeltest :results output
str(babeltest)
#+end_src

#+results:
: 'data.frame':	10 obs. of  4 variables:
:  $ ID  : int  1 2 3 4 5 6 7 8 9 10
:  $ var1: int  34 56 78 34 56 23 45 23 89 46
:  $ var2: int  1 4 3 5 6 7 5 6 7 4
:  $ var3: int  400 499 500 600 500 300 200 340 400 450
-------------------------------------------------------------------------------

>
> #+resname: babeltest
> | "ID" | "var1" | "var2" | "var3" |
> |------+--------+--------+--------|
> |    1 |     34 |      1 |    400 |
> |    2 |     56 |      4 |    499 |
> |    3 |     78 |      3 |    500 |
> |    4 |     34 |      5 |    600 |
> |    5 |     56 |      6 |    500 |
> |    6 |     23 |      7 |    300 |
> |    7 |     45 |      5 |    200 |
> |    8 |     23 |      6 |    340 |
> |    9 |     89 |      7 |    400 |
> |   10 |     46 |      4 |    450 |
>
>
>
> #+begin_src R :session babeltest
> summary(babeltest)
> #+end_src
>
> #+resname:
> | "Min.   : 1.00" | "Min.   :23.0" | "Min.   :1.0" | "Min.   :200.0" |
> | "1st Qu.: 3.25" | "1st Qu.:34.0" | "1st Qu.:4.0" | "1st Qu.:355.0" |
> | "Median : 5.50" | "Median :45.5" | "Median :5.0" | "Median :425.0" |
> | "Mean   : 5.50" | "Mean   :48.4" | "Mean   :4.8" | "Mean   :418.9" |
> | "3rd Qu.: 7.75" | "3rd Qu.:56.0" | "3rd Qu.:6.0" | "3rd Qu.:499.8" |
> | "Max.   :10.00" | "Max.   :89.0" | "Max.   :7.0" | "Max.   :600.0" |
>
> #+begin_src R :session babeltest
> str(babeltest)
> #+end_src
>
> #+resname:
>
> _______________________________________________
> 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

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

* Re: Re: [babel] R - variable names in summary
  2009-12-09  4:38 ` Austin Frank
@ 2009-12-09 16:46   ` Graham Smith
  0 siblings, 0 replies; 14+ messages in thread
From: Graham Smith @ 2009-12-09 16:46 UTC (permalink / raw)
  To: emacs-orgmode

Austin

> This is help from the R side, not from the org-babel side.  If these
> suggestions don't work, one of the babelers will have to step in.
>
> Many functions that print output to the interactive buffer will not
> produce that output when called outside of the interactive buffer.  For
> these functions, if you wrap them in print() you can usually get the

Thanks, yes, I have that problem with lattice plots and sweave, didn't
think about it for this problem,

However, some examples that Tom gave me use str unwrapped so I assume
it should work.

But I will bear that in mind.

Graham

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

* Re: [babel] R - variable names in summary
  2009-12-09 16:38 ` Dan Davison
@ 2009-12-09 17:05   ` Graham Smith
  2009-12-09 19:14     ` Dan Davison
  0 siblings, 1 reply; 14+ messages in thread
From: Graham Smith @ 2009-12-09 17:05 UTC (permalink / raw)
  To: emacs-orgmode

Dan,

>> The colnames t works as expected, but how do I then see the variable
>> names when using the summary command,
>
> Just use :colnames t again for that.

Thanks again, I almost had this solved but in

#+begin_src R :session babeltest :colnames t

I hadn't left a space between the end of babeltest and the :

But I would never have figured out the :results output  method, however.

Next question is is to do with output with things like summary. In R
if you have lots of variables,the output wraps so it fits on the
screen. With babel it runs off the edge of the page. is there a quick
way of getting the output to fit an anticipated a4 pdf output.

I appreciate this may be more an Emacs/orgmode question than a babel one.

Graham

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

* Re: [babel] R - variable names in summary
  2009-12-09 17:05   ` Graham Smith
@ 2009-12-09 19:14     ` Dan Davison
  2009-12-09 20:33       ` Graham Smith
  2009-12-09 20:49       ` Austin Frank
  0 siblings, 2 replies; 14+ messages in thread
From: Dan Davison @ 2009-12-09 19:14 UTC (permalink / raw)
  To: Graham Smith; +Cc: emacs-orgmode

Graham Smith <myotisone@gmail.com> writes:

> Dan,
>
>>> The colnames t works as expected, but how do I then see the variable
>>> names when using the summary command,
>>
>> Just use :colnames t again for that.
>
> Thanks again, I almost had this solved but in
>
> #+begin_src R :session babeltest :colnames t
>
> I hadn't left a space between the end of babeltest and the :
>
> But I would never have figured out the :results output  method, however.

OK, it would be really helpful if you could let us know how we should
improve the documentation of it.

>
> Next question is is to do with output with things like summary. In R
> if you have lots of variables,the output wraps so it fits on the
> screen. With babel it runs off the edge of the page. is there a quick
> way of getting the output to fit an anticipated a4 pdf output.

I'd suggest using :results output, and controlling the width of the
output with options(width=whatever) in R. E.g.

#+begin_src R :session babeltest :colnames t :results output
options(width=80)
summary(cbind(babeltest, babeltest))
#+end_src

#+results:
#+begin_example
       ID             var1           var2          var3             ID       
 Min.   : 1.00   Min.   :23.0   Min.   :1.0   Min.   :200.0   Min.   : 1.00  
 1st Qu.: 3.25   1st Qu.:34.0   1st Qu.:4.0   1st Qu.:355.0   1st Qu.: 3.25  
 Median : 5.50   Median :45.5   Median :5.0   Median :425.0   Median : 5.50  
 Mean   : 5.50   Mean   :48.4   Mean   :4.8   Mean   :418.9   Mean   : 5.50  
 3rd Qu.: 7.75   3rd Qu.:56.0   3rd Qu.:6.0   3rd Qu.:499.8   3rd Qu.: 7.75  
 Max.   :10.00   Max.   :89.0   Max.   :7.0   Max.   :600.0   Max.   :10.00  
      var1           var2          var3      
 Min.   :23.0   Min.   :1.0   Min.   :200.0  
 1st Qu.:34.0   1st Qu.:4.0   1st Qu.:355.0  
 Median :45.5   Median :5.0   Median :425.0  
 Mean   :48.4   Mean   :4.8   Mean   :418.9  
 3rd Qu.:56.0   3rd Qu.:6.0   3rd Qu.:499.8  
 Max.   :89.0   Max.   :7.0   Max.   :600.0
#+end_example

I don't think either org or org-babel has any way to automatically wrap
wide tables. Also bear in mind the tranpose function in R (t), although
that's not helpful for this summary output, which is a rather weird
table, not a standard matrix or data frame.

Dan

>
> I appreciate this may be more an Emacs/orgmode question than a babel one.
>
> Graham
>
>
> _______________________________________________
> 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

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

* Re: [babel] R - variable names in summary
  2009-12-09 19:14     ` Dan Davison
@ 2009-12-09 20:33       ` Graham Smith
  2009-12-09 20:44         ` Dan Davison
  2009-12-09 20:51         ` Thomas S. Dye
  2009-12-09 20:49       ` Austin Frank
  1 sibling, 2 replies; 14+ messages in thread
From: Graham Smith @ 2009-12-09 20:33 UTC (permalink / raw)
  To: emacs-orgmode

Dan,

That's great, I am beginning to grasp how this works

>> But I would never have figured out the :results output  method, however.
>
> OK, it would be really helpful if you could let us know how we should
> improve the documentation of it.

I'm not sure if I'm the one to ask about the documentation, as I
struggled with most of it, but that is my problem and probably not
typical. I'm also still very much trying to get to grips with Emacs
and orgmode.

Not being a programmer, I find the terminology and phrasing of these
sorts of things difficult to follow, and need examples to copy , and
then try and extract from the documentation and other examples, how
things work.

My problem was therefore  the lack of examples specific to R.  My
guess is that the majority of emacs/orgmode users won't have the same
problems.

Graham

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

* Re: [babel] R - variable names in summary
  2009-12-09 20:33       ` Graham Smith
@ 2009-12-09 20:44         ` Dan Davison
  2009-12-09 21:00           ` Graham Smith
  2009-12-09 20:51         ` Thomas S. Dye
  1 sibling, 1 reply; 14+ messages in thread
From: Dan Davison @ 2009-12-09 20:44 UTC (permalink / raw)
  To: Graham Smith; +Cc: emacs-orgmode

Graham Smith <myotisone@gmail.com> writes:

> Dan,
>
> That's great, I am beginning to grasp how this works
>
>>> But I would never have figured out the :results output  method, however.
>>
>> OK, it would be really helpful if you could let us know how we should
>> improve the documentation of it.
>
> I'm not sure if I'm the one to ask about the documentation, as I
> struggled with most of it, but that is my problem and probably not
> typical. I'm also still very much trying to get to grips with Emacs
> and orgmode.
>
> Not being a programmer, I find the terminology and phrasing of these

I wouldn't classify someone who analyses their data with R as a
non-programmer.

> sorts of things difficult to follow, and need examples to copy , and
> then try and extract from the documentation and other examples, how
> things work.
>
> My problem was therefore  the lack of examples specific to R.

Yes, I can see that. I can imagine that if shell/python/ruby code looks
alien then the examples using those languages are not very
inviting. Thanks for pointing that out. Tom Dye and Eric and I are
working on documentation, including a Worg page specifically for R with
org-babel. Currently it doesn't contain anything you don't know but
we'll let you know when the first version goes up on Worg.

Dan


>  My
> guess is that the majority of emacs/orgmode users won't have the same
> problems.
>
> Graham
>
>
> _______________________________________________
> 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

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

* Re: [babel] R - variable names in summary
  2009-12-09 19:14     ` Dan Davison
  2009-12-09 20:33       ` Graham Smith
@ 2009-12-09 20:49       ` Austin Frank
  2009-12-09 21:12         ` Graham Smith
  2009-12-09 22:28         ` Dan Davison
  1 sibling, 2 replies; 14+ messages in thread
From: Austin Frank @ 2009-12-09 20:49 UTC (permalink / raw)
  To: emacs-orgmode


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

On Wed, Dec 09 2009, Dan Davison wrote:

> Graham Smith <myotisone@gmail.com> writes:

>> Next question is is to do with output with things like summary. In R
>> if you have lots of variables,the output wraps so it fits on the
>> screen. With babel it runs off the edge of the page. is there a quick
>> way of getting the output to fit an anticipated a4 pdf output.
>
> I'd suggest using :results output, and controlling the width of the
> output with options(width=whatever) in R. E.g.
>
> #+begin_src R :session babeltest :colnames t :results output
> options(width=80)
> summary(cbind(babeltest, babeltest))
> #+end_src

I don't know whether this will end up fitting into your setup, but
there's an emacs function `ess-execute-screen-options' that does what
Dan just suggested on a per-session basis taking the width of the
current buffer into account.  Even if it doesn't help with org-bable, it
makes life in ESS much pleasanter.

You can also look at the latex() function in the R package Hmisc and the
function xtable() from the R package xtable.  For data frames, matrices,
and some common summary functions, these functions will create a latex
table out of your R object.  Maybe Dan can suggest how latex code
generated in R could be properly included and typeset in org-babel.

HTH,
/au

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

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

[-- Attachment #2: 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

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

* Re: [babel] R - variable names in summary
  2009-12-09 20:33       ` Graham Smith
  2009-12-09 20:44         ` Dan Davison
@ 2009-12-09 20:51         ` Thomas S. Dye
  2009-12-09 21:06           ` Graham Smith
  1 sibling, 1 reply; 14+ messages in thread
From: Thomas S. Dye @ 2009-12-09 20:51 UTC (permalink / raw)
  To: Graham Smith; +Cc: emacs-orgmode

Hi Graham,

On Dec 9, 2009, at 10:33 AM, Graham Smith wrote:

> Dan,
>
> That's great, I am beginning to grasp how this works
>
>>> But I would never have figured out the :results output  method,  
>>> however.
>>
>> OK, it would be really helpful if you could let us know how we should
>> improve the documentation of it.
>
> I'm not sure if I'm the one to ask about the documentation, as I
> struggled with most of it, but that is my problem and probably not
> typical. I'm also still very much trying to get to grips with Emacs
> and orgmode.
>
> Not being a programmer, I find the terminology and phrasing of these
> sorts of things difficult to follow, and need examples to copy , and
> then try and extract from the documentation and other examples, how
> things work.
>
> My problem was therefore  the lack of examples specific to R.  My
> guess is that the majority of emacs/orgmode users won't have the same
> problems.
>
> Graham

I'd like to second Dan's invitation and ask that you drop a note to  
the list when you find something difficult to understand in the  
documentation.  There isn't anything about the use of Org-babel (or  
Org-mode) that a non-programmer shouldn't be able to follow.

BTW, I agree with you about the difficult terminology and phrasing in  
the Org-babel documentation.  It should be possible to make the  
definitions of terms and the distinctions they index more accessible.   
So, please let the list know when something trips you up.

When you find an example that fills a gap you perceive in the  
documentation, please pass that along, too.  The more examples the  
better.

I'm glad to hear you've made it over the steep part of the Org-babel  
learning curve and that it is working for you now.  If your experience  
is like mine you'll soon be wondering how you ever managed without it.

All the best,
Tom

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

* Re: [babel] R - variable names in summary
  2009-12-09 20:44         ` Dan Davison
@ 2009-12-09 21:00           ` Graham Smith
  0 siblings, 0 replies; 14+ messages in thread
From: Graham Smith @ 2009-12-09 21:00 UTC (permalink / raw)
  To: emacs-orgmode

Dan


>> Not being a programmer, I find the terminology and phrasing of these
>
> I wouldn't classify someone who analyses their data with R as a
> non-programmer.

Mmmm, I can see why you would say this, but I don't really program in
R, but have collected a library of R code over the years which I know
how to use and tweak.


>> My problem was therefore  the lack of examples specific to R.
>
> Yes, I can see that. I can imagine that if shell/python/ruby code looks
> alien then the examples using those languages are not very
> inviting. Thanks for pointing that out. Tom Dye and Eric and I are
> working on documentation, including a Worg page specifically for R with
> org-babel. Currently it doesn't contain anything you don't know but
> we'll let you know when the first version goes up on Worg.

I look forward to it.

Thanks again,

Graham

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

* Re: [babel] R - variable names in summary
  2009-12-09 20:51         ` Thomas S. Dye
@ 2009-12-09 21:06           ` Graham Smith
  0 siblings, 0 replies; 14+ messages in thread
From: Graham Smith @ 2009-12-09 21:06 UTC (permalink / raw)
  To: emacs-orgmode

Tom,

Thanks for your comments.

> When you find an example that fills a gap you perceive in the documentation,
> please pass that along, too.  The more examples the better.

Now that I have basics working, I will try and use it for something
specific over the next few weeks and certainly feedback anything I
think might be helpful.

Graham

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

* Re: Re: [babel] R - variable names in summary
  2009-12-09 20:49       ` Austin Frank
@ 2009-12-09 21:12         ` Graham Smith
  2009-12-09 22:28         ` Dan Davison
  1 sibling, 0 replies; 14+ messages in thread
From: Graham Smith @ 2009-12-09 21:12 UTC (permalink / raw)
  To: Austin Frank; +Cc: emacs-orgmode

Austin

> I don't know whether this will end up fitting into your setup, but
> there's an emacs function `ess-execute-screen-options' that does what
> Dan just suggested on a per-session basis taking the width of the
> current buffer into account.  Even if it doesn't help with org-bable, it
> makes life in ESS much pleasanter.

Wasn't aware of this, but will have a look

> You can also look at the latex() function in the R package Hmisc and the
> function xtable() from the R package xtable.  For data frames, matrices,
> and some common summary functions, these functions will create a latex
> table out of your R object.  Maybe Dan can suggest how latex code
> generated in R could be properly included and typeset in org-babel.

I have played with xtable() in the past, but I am now rethinking
things now that babel looks so promising.

Thanks for the pointers.

Graham

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

* Re: Re: [babel] R - variable names in summary
  2009-12-09 20:49       ` Austin Frank
  2009-12-09 21:12         ` Graham Smith
@ 2009-12-09 22:28         ` Dan Davison
  1 sibling, 0 replies; 14+ messages in thread
From: Dan Davison @ 2009-12-09 22:28 UTC (permalink / raw)
  To: Austin Frank; +Cc: emacs-orgmode

> You can also look at the latex() function in the R package Hmisc and the
> function xtable() from the R package xtable.  For data frames, matrices,
> and some common summary functions, these functions will create a latex
> table out of your R object.  Maybe Dan can suggest how latex code
> generated in R could be properly included and typeset in org-babel.

Hi Austin,

If one does need to resort to generating latex code directly from a
language then we have ':results latex', which ensures that the results
are wrapped in a begin_latex block. And as you point out, those R
functions could have their place even in the org-babel framework, as
they can make tabular latex output out of very non-tabular stuff[1]
E.g. below[2].

Dan

Footnotes:

[1] Of course it would be better if they generated org tables; maybe we
should start an R package for it (oRg?), one day.

[2] This example summarises a linear regression fit. Neither the printed
representation nor the value of summary(lm(y ~ x)) is at all tabular,
but the xtable function outputs a latex table which can be included in
the org buffer and thus in exported latex.

#+begin_src R :results output latex
library(xtable)
x <- rnorm(100)
y <- x + rnorm(100)
xtable(summary(lm(y ~ x)))
#+end_src

#+results:
#+BEGIN_LaTeX
% latex table generated in R 2.9.2 by xtable 1.5-5 package
% Wed Dec  9 17:17:53 2009
\begin{table}[ht]
\begin{center}
\begin{tabular}{rrrrr}
  \hline
 & Estimate & Std. Error & t value & Pr($>$$|$t$|$) \\ 
  \hline
(Intercept) & -0.0743 & 0.0969 & -0.77 & 0.4454 \\ 
  x & 1.0707 & 0.0923 & 11.60 & 0.0000 \\ 
   \hline
\end{tabular}
\end{center}
\end{table}
#+END_LaTeX

>
> HTH,
> /au

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

end of thread, other threads:[~2009-12-09 22:28 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-12-08 23:50 [babel] R - variable names in summary Graham Smith
2009-12-09  4:38 ` Austin Frank
2009-12-09 16:46   ` Graham Smith
2009-12-09 16:38 ` Dan Davison
2009-12-09 17:05   ` Graham Smith
2009-12-09 19:14     ` Dan Davison
2009-12-09 20:33       ` Graham Smith
2009-12-09 20:44         ` Dan Davison
2009-12-09 21:00           ` Graham Smith
2009-12-09 20:51         ` Thomas S. Dye
2009-12-09 21:06           ` Graham Smith
2009-12-09 20:49       ` Austin Frank
2009-12-09 21:12         ` Graham Smith
2009-12-09 22:28         ` Dan Davison

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).