emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Dan Davison <davison@stats.ox.ac.uk>
To: Graham Smith <myotisone@gmail.com>
Cc: emacs-orgmode@gnu.org
Subject: Re: [babel] R - variable names in summary
Date: Wed, 09 Dec 2009 11:38:18 -0500	[thread overview]
Message-ID: <87k4wwf6h1.fsf@stats.ox.ac.uk> (raw)
In-Reply-To: <2c75873c0912081550m5da3861fgb3a14f047f8638ae@mail.gmail.com> (Graham Smith's message of "Tue, 8 Dec 2009 23:50:44 +0000")

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

  parent reply	other threads:[~2009-12-09 16:38 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

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=87k4wwf6h1.fsf@stats.ox.ac.uk \
    --to=davison@stats.ox.ac.uk \
    --cc=emacs-orgmode@gnu.org \
    --cc=myotisone@gmail.com \
    /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).