emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Babel - importing a data file- missing header row
@ 2009-12-08 16:41 Graham Smith
  2009-12-08 17:46 ` [babel] " Dan Davison
  0 siblings, 1 reply; 3+ messages in thread
From: Graham Smith @ 2009-12-08 16:41 UTC (permalink / raw)
  To: emacs-orgmode

I need a bit of help importing a data file into orgmode/babel.

The import doesn't seem to know about having a header row

#+srcname:woodland
#+begin_src R
read.table("/home/graham/Dropbox/College/BY4001/WoodlandData/BY4001WoodlandDataFinal.txt",header=TRUE)
#+end_src

#+resname: woodland
| "V1.1"  | "v" | 0 | 0 | 0 |  0 | 0 |  0 |  0 |  0 |  0 |  0 |  0 |
0 |  0 |  0 | 0 |  0 | 0 |  0 |  0 |  0 |  0 | 0 |  0 | 0 | 0 |  0 |
0 |  0 | 0 |  0 |  5 |  0 |  0 | 10 |  0 | 0 |  0 | 100 |  0 |  3 | B


But strangely if I change the command and run the names(woodland)
after the import, I get a table of variable names but no data. I'm not
sure if the data is there but hidden as I can't get any commands to
work on the woodland object.

* Woodland Data
#+srcname:woodland
#+begin_src R
woodland<-read.table("/home/graham/Dropbox/College/BY4001/WoodlandData/BY4001WoodlandDataFinal.txt",header=TRUE)
names(woodland)
#+end_src

#+resname: woodland
| "ID"           |
| "wood"         |
| "Ajug.Rept"    |
| "Ange.sylv"    |
| "Brac.sylv"    |
| "Brom.ramo"    |
| "Care.pend"    |
| "Care.remo"    |
| "Care.sylv"    |
| "Cirs.palu"    |
| "Cory.avel"    |
| "Desc.caes"    |
| "Dryo.fili"    |
| "Endy.non"     |
| "Euph.amyg"    |

So it seems I already need some more help.

Graham

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

* Re: [babel] Babel - importing a data file- missing header row
  2009-12-08 16:41 Babel - importing a data file- missing header row Graham Smith
@ 2009-12-08 17:46 ` Dan Davison
  2009-12-08 18:08   ` Graham Smith
  0 siblings, 1 reply; 3+ messages in thread
From: Dan Davison @ 2009-12-08 17:46 UTC (permalink / raw)
  To: Graham Smith; +Cc: emacs-orgmode

Graham Smith <myotisone@gmail.com> writes:

> I need a bit of help importing a data file into orgmode/babel.
>
> The import doesn't seem to know about having a header row
>

Hi Graham,

Could you post the first few lines of your data file, or a small example
with the same format, as I don't completely understand the output you
are getting.

But try using the ':colnames t' header argument. For example, if I have
this data file (space-separated, header line has same num entries as
data rows).

-----------------------------
ID wood A.reptans E.amygdaloides   
a wood1 5 10
b wood2 1 0
-----------------------------

Then I get

#+srcname:woodland
#+begin_src R
read.table("/tmp/woodlands.txt",header=TRUE)
#+end_src

#+results: woodland
| "a" | "wood1" | 5 | 10 |
| "b" | "wood2" | 1 |  0 |

And if I use the colnames header argument I get

#+srcname:woodland
#+begin_src R :colnames t
read.table("/tmp/woodlands.txt",header=TRUE)
#+end_src

#+results: woodland
| "ID" | "wood"  | "A.reptans" | "E.amygdaloides" |
|------+---------+-------------+------------------|
| "a"  | "wood1" |           5 |               10 |
| "b"  | "wood2" |           1 |                0 |

Also, I recommend working with the :session header argument. Then after
you evaluate an org-babel block, you can go to the ESS session and
examine the R objects it has created. You'd need to save the data frame
to a variable of course, so something like this

#+srcname:woodland
#+begin_src R :colnames t :session
  woodlands <- read.table("/tmp/woodlands.txt",header=TRUE)
  woodlands
#+end_src

Now if I switch to the *R* buffer, I can see what it has done:


First you'll see some lines like this; these reflect what org-babel did

-----------------------------------------------------------------------------------------------------------
> 
woodlands <- read.table("/tmp/woodlands.txt",header=TRUE)
write.table(.Last.value, file="/tmp/org-babel-R6645iE0", sep="\t", na="nil",row.names=FALSE, col.names=TRUE, quote=FALSE)
'org_babel_R_eoe'

> woodlands <- read.table("/tmp/woodlands.txt",header=TRUE)
> write.table(.Last.value, file="/tmp/org-babel-R6645iE0", sep="\t", na="nil",row.names=FALSE, col.names=TRUE, quote=FALSE)
> 'org_babel_R_eoe'         
[1] "org_babel_R_eoe"
-----------------------------------------------------------------------------------------------------------\
Ignore the org_babel_R_eoe stuff, that's to do with org-babel internals.

Now you can check that your variable looks sensible:

-----------------------------------------------------------------------------------------------------------\
> woodlands
  ID  wood A.reptans E.amygdaloides
1  a wood1         5             10
2  b wood2         1              0
> 
-----------------------------------------------------------------------------------------------------------\

Dan

p.s. Please include the string "[babel]" in the subject line!

> #+srcname:woodland
> #+begin_src R
> read.table("/home/graham/Dropbox/College/BY4001/WoodlandData/BY4001WoodlandDataFinal.txt",header=TRUE)
> #+end_src
>
> #+resname: woodland
> | "V1.1"  | "v" | 0 | 0 | 0 |  0 | 0 |  0 |  0 |  0 |  0 |  0 |  0 |
> 0 |  0 |  0 | 0 |  0 | 0 |  0 |  0 |  0 |  0 | 0 |  0 | 0 | 0 |  0 |
> 0 |  0 | 0 |  0 |  5 |  0 |  0 | 10 |  0 | 0 |  0 | 100 |  0 |  3 | B
>
>
> But strangely if I change the command and run the names(woodland)
> after the import, I get a table of variable names but no data. I'm not
> sure if the data is there but hidden as I can't get any commands to
> work on the woodland object.
>
> * Woodland Data
> #+srcname:woodland
> #+begin_src R
> woodland<-read.table("/home/graham/Dropbox/College/BY4001/WoodlandData/BY4001WoodlandDataFinal.txt",header=TRUE)
> names(woodland)
> #+end_src
>
> #+resname: woodland
> | "ID"           |
> | "wood"         |
> | "Ajug.Rept"    |
> | "Ange.sylv"    |
> | "Brac.sylv"    |
> | "Brom.ramo"    |
> | "Care.pend"    |
> | "Care.remo"    |
> | "Care.sylv"    |
> | "Cirs.palu"    |
> | "Cory.avel"    |
> | "Desc.caes"    |
> | "Dryo.fili"    |
> | "Endy.non"     |
> | "Euph.amyg"    |
>
> So it seems I already need some more help.
>
> 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] 3+ messages in thread

* Re: [babel] Babel - importing a data file- missing header row
  2009-12-08 17:46 ` [babel] " Dan Davison
@ 2009-12-08 18:08   ` Graham Smith
  0 siblings, 0 replies; 3+ messages in thread
From: Graham Smith @ 2009-12-08 18:08 UTC (permalink / raw)
  To: emacs-orgmode

Dan,

Using session gets everything working as I expect it to, at least so
far it does. I will work through the other aspects you suggest but for
now its looking good.

> Could you post the first few lines of your data file, or a small example
> with the same format, as I don't completely understand the output you
> are getting.

The difficulty in understanding the output I posted was probably
because while it looked OK when I posted it, the version that appeared
wrapped twice. But its working now.

> p.s. Please include the string "[babel]" in the subject line!

Ah yes, I misunderstood your first request and just thought you meant
to make sure babel was in the subject line,which I did,  but you mean
[babel] not just babel.

Many thanks again,

Graham

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

end of thread, other threads:[~2009-12-08 18:08 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-12-08 16:41 Babel - importing a data file- missing header row Graham Smith
2009-12-08 17:46 ` [babel] " Dan Davison
2009-12-08 18:08   ` Graham Smith

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