From mboxrd@z Thu Jan 1 00:00:00 1970 From: Dan Davison Subject: Re: [babel] Babel - importing a data file- missing header row Date: Tue, 08 Dec 2009 12:46:53 -0500 Message-ID: <871vj573zm.fsf@stats.ox.ac.uk> References: <2c75873c0912080841j39a13a55t35c737be3455e211@mail.gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NI49O-00081t-OO for emacs-orgmode@gnu.org; Tue, 08 Dec 2009 12:47:02 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NI49K-0007wa-Sy for emacs-orgmode@gnu.org; Tue, 08 Dec 2009 12:47:02 -0500 Received: from [199.232.76.173] (port=51306 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NI49K-0007wI-MF for emacs-orgmode@gnu.org; Tue, 08 Dec 2009 12:46:58 -0500 Received: from markov.stats.ox.ac.uk ([163.1.210.1]:39397) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NI49K-00043I-Bh for emacs-orgmode@gnu.org; Tue, 08 Dec 2009 12:46:58 -0500 In-Reply-To: <2c75873c0912080841j39a13a55t35c737be3455e211@mail.gmail.com> (Graham Smith's message of "Tue, 8 Dec 2009 16:41:22 +0000") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Graham Smith Cc: emacs-orgmode@gnu.org Graham Smith 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