Graham Smith myotis...@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
___
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