From mboxrd@z Thu Jan 1 00:00:00 1970 From: tsd@tsdye.com (Thomas S. Dye) Subject: Re: import R data frame into org-mode table Date: Wed, 17 Jul 2013 12:48:00 -1000 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:35438) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UzaWA-00025S-Qy for emacs-orgmode@gnu.org; Wed, 17 Jul 2013 18:48:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UzaW6-0002sa-RW for emacs-orgmode@gnu.org; Wed, 17 Jul 2013 18:48:18 -0400 Received: from oproxy14-pub.unifiedlayer.com ([67.222.51.224]:34621) by eggs.gnu.org with smtp (Exim 4.71) (envelope-from ) id 1UzaW6-0002pT-K3 for emacs-orgmode@gnu.org; Wed, 17 Jul 2013 18:48:14 -0400 In-Reply-To: (Rob Stewart's message of "Tue, 16 Jul 2013 16:19:07 +0100") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Rob Stewart Cc: emacs-orgmode@gnu.org Rob Stewart writes: > I have an R script that generates a data frame, that I export to a CSV > file. The data looks something like this: > > "","Variant","Xaxis","N","mean","sd","se" > "1","line1",10,5,111.11,9.33,3.11 > "1","line1",20,5,112.11,9.13,3.14 > "1","line1",30,5,113.11,9.43,3.10 > "1","line2",10,5,101.11,8.33,2.11 > "1","line2",20,5,100.11,8.13,2.12 > "1","line2",30,5,108.11,8.03,2.10 > > I have an ongoing org-mode document in which I'd like to report this > data. I'd like to add a table that looks something like this: > > | Variant | X Axis | Y Axis | N | Mean | Standard Deviation | > Standard Error | > |----------------------------------------------------------------------------| > > The data will change frequently over the coming months. I'd like > org-mode to auto-magically read a CSV file, to construct my org-table > on-the-fly. I'd hoping to avoid copying and pasting results each time. > > Is there some org-mode or emacs+ESS magic I can use to populate my > empty table, with source data from my CSV file? > > -- > Rob Hi Rob, Andreas' post answers your specific question. In your situation, I typically don't run through a csv file, but just write the R script so the data frame is returned to the Org mode buffer as the result of the source code block. As for the translation of column heads, see the ascii package for R, which has a print() routine that recognizes Org mode as a type of output, and which has facilities for formatting column names. Here is an example from some work in progress that uses a session: #+property: exports results #+property: colnames yes #+property: session *adzes* #+name: lda-mid-z #+header: :results output org #+begin_src R y <- edxrf[edxrf$lab=='UH-Hilo',] fit <- lda(as.factor(site) ~ rb_ppm + sr_ppm + y_ppm + zr_ppm + nb_ppm, data=y, na.action="na.omit", CV=TRUE) adzes <- y$site=='unknown' cap <- "Assignment of unknowns to sources" z <- ascii(cbind(BPBM=y$bpbm[adzes],round(fit$posterior[adzes,],2)),header=T,include.colnames=T,caption=cap) print(z,type="org") rm(y,fit,adzes,cap,z) #+end_src #+RESULTS: lda-mid-z #+BEGIN_ORG #+CAPTION: Assignment of unknowns to sources | BPBM | Haleakala | Kilauea | Mauna Kea | Nu`u | Pololu | Waiahole | unknown | |---------------------------+-----------+---------+-----------+------+--------+----------+---------| | 1985.134.01 adze | 0 | 0.1 | 0 | 0 | 0 | 0.64 | 0.27 | | 50-HA-1349-G-5 adze | 0 | 0.85 | 0 | 0 | 0 | 0 | 0.14 | | 50-HA-900-P24-1 microadze | 0 | 0 | 1 | 0 | 0 | 0 | 0 | ... hth, Tom -- Thomas S. Dye http://www.tsdye.com