From mboxrd@z Thu Jan 1 00:00:00 1970 From: Rainer M Krug Subject: Re: org tables into R? Date: Tue, 06 Jan 2015 12:02:48 +0100 Message-ID: References: <874ms6w0it.fsf@gmail.com> <87zj9xa1ni.fsf@nicolasgoaziou.fr> Mime-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha1; protocol="application/pgp-signature" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:51531) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y8Ruh-0000hz-13 for emacs-orgmode@gnu.org; Tue, 06 Jan 2015 06:03:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Y8Ruc-00040u-Sp for emacs-orgmode@gnu.org; Tue, 06 Jan 2015 06:03:02 -0500 Received: from mail-we0-f176.google.com ([74.125.82.176]:46034) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y8Ruc-00040n-Iq for emacs-orgmode@gnu.org; Tue, 06 Jan 2015 06:02:58 -0500 Received: by mail-we0-f176.google.com with SMTP id w61so9410087wes.7 for ; Tue, 06 Jan 2015 03:02:57 -0800 (PST) In-Reply-To: (Andreas Leha's message of "Tue, 06 Jan 2015 10:14:30 +0000") 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: Andreas Leha Cc: emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Andreas Leha writes: > Hi Aaron and Nicolas, Sorry for coming so late to this topic - I should try to figure out what is causing the problem as I am the one responsible for this code... > > Thanks for partly fixing this issue. Unfortunately, when working with > source block interactively the issue persists for me. If in the same > sample file I view the source block via 'C-c C-v v' and step through the > generated code line-by-line, the table is again not split into columns. > > This time I immediately tried with 'emacs -Q' and I can reproduce the > issue. > > Here is the ecm again: > > * test > #+NAME: data > | A | B | C | > |-----+----+----| > | 115 | 76 | 60 | > | 124 | 78 | 55 | > | 118 | 73 | 65 | > | 114 | 75 | 61 | > | 108 | 74 | 82 | > > and pass it into R like this, then evaluation (C-c C-c) works, but > stepping through the code generated for viewing (C-c C-v v) does not: > > #+BEGIN_SRC R :results output :exports both :session :var data.table=3Dda= ta > names(data.table) > head(data.table) > #+END_SRC > > #+results: > : [1] "A" "B" "C" > : A B C > : 1 115 76 60 > : 2 124 78 55 > : 3 118 73 65 > : 4 114 75 61 > : 5 108 74 82 > > #+begin_src emacs-lisp > (concat > (replace-regexp-in-string " on .*" "" (emacs-version)) > "\n" > (replace-regexp-in-string " @.*" ")" (org-version nil t)) > "\n" > (replace-regexp-in-string "].*" "]" (ess-version))) > #+end_src > > #+results: > : GNU Emacs 24.4.50.1 (x86_64-apple-darwin13.3.0, NS appkit-1265.21 Versi= on 10.9.4 (Build 13E28)) > : of 2014-09-02 > : Org-mode version 8.3beta (release_8.3beta-717-ga8096c) > : ess-version: 14.05 [git: 4283f1304a54502c42707b6a4ba347703f0992dd] > ,---- | #+RESULTS: | : GNU Emacs 24.4.1 (x86_64-apple-darwin14.0.0, Carbon Version 157 AppKit = 1343.16) | : of 2014-11-24 | : Org-mode version 8.3beta (release_8.3beta-695-g390015) | : ess-version: 14.09 [svn: 6041 (2014-09-13)] `---- I get the same in the preview, but it works for me. I do not use -q. ,---- | > data.table <- local({ | + con <- textConnection( | + "\"A\" \"B\" \"C\" | + \"115\" \"76\" \"60\" | + \"124\" \"78\" \"55\" | + \"118\" \"73\" \"65\" | + \"114\" \"75\" \"61\" | + \"108\" \"74\" \"82\"" | + ) | + res <- utils::read.table( | + con, | + header =3D TRUE, | + row.names =3D NULL, | + sep =3D "\t", | + as.is =3D TRUE | + ) | + close(con) | + res | + }) | > names(data.table) | [1] "A" "B" "C" | > head(data.table) | A B C | 1 115 76 60 | 2 124 78 55 | 3 118 73 65 | 4 114 75 61 | 5 108 74 82 | >=20 `---- > > Here is what I see in the org babel preview: > This might be due to temail, but you don't have tabs (\t) between your entries below - could you verify if this is the case? If yes, this might be a locale issue (would be strange)? > data.table <- local({ > con <- textConnection( > "\"A\" \"B\" \"C\" > \"115\" \"76\" \"60\" > \"124\" \"78\" \"55\" > \"118\" \"73\" \"65\" > \"114\" \"75\" \"61\" > \"108\" \"74\" \"82\"" > ) > res <- utils::read.table( > con, > header =3D TRUE, > row.names =3D NULL, > sep =3D "\t", > as.is =3D TRUE > ) > close(con) > res > }) > names(data.table) > head(data.table) One solution would be to insert (instead of the tab character) "\t" to separate the fields? You could try and modify the ob-R-transfer-variable-table-with-header - From=20the help: ,---- | ob-R-transfer-variable-table-with-header is a variable defined in `ob-R.e= l'. | Its value is | "%s <- local({\n con <- textConnection(\n %S\n )\n res = <- utils::read.table(\n con,\n header =3D %s,\n row.na= mes =3D %s,\n sep =3D \"\\t\",\n as.is =3D TRUE\n = )\n close(con)\n res\n })" |=20 | This variable may be risky if used as a file-local variable. |=20 | Documentation: | R code used to transfer a table defined as a variable from org to R. |=20 | This function is used when the table contains a header. `---- This is passed to the (format) function and one might be able to change something there. Cheers, Rainer > > > And finally, here is my R session, when I step through the code: > > > R version 3.1.2 (2014-10-31) -- "Pumpkin Helmet" > Copyright (C) 2014 The R Foundation for Statistical Computing > Platform: x86_64-apple-darwin10.8.0 (64-bit) > > R is free software and comes with ABSOLUTELY NO WARRANTY. > You are welcome to redistribute it under certain conditions. > Type 'license()' or 'licence()' for distribution details. > > Natural language support but running in an English locale > > R is a collaborative project with many contributors. > Type 'contributors()' for more information and > 'citation()' on how to cite R or R packages in publications. > > Type 'demo()' for some demos, 'help()' for on-line help, or > 'help.start()' for an HTML browser interface to help. > Type 'q()' to quit R. > >> > options(STERM=3D'iESS', str.dendrogram.last=3D"'", editor=3D'emacsclie= nt', show.error.locations=3DTRUE) >> data.table <- local({ > + con <- textConnection( > + "\"A\" \"B\" \"C\" > + \"115\" \"76\" \"60\" > + \"124\" \"78\" \"55\" > + \"118\" \"73\" \"65\" > + \"114\" \"75\" \"61\" > + \"108\" \"74\" \"82\"" > + ) > + res <- utils::read.table( > + con, > + header =3D TRUE, > + row.names =3D NULL, > + sep =3D "\t", > + as.is =3D TRUE > + ) > + close(con) > + res > + }) >> names(data.table) > [1] "A...B...C" >> head(data.table) > A...B...C > 1 115 76 60 > 2 124 78 55 > 3 118 73 65 > 4 114 75 61 > 5 108 74 82 > > > Regards, > Andreas > > > =2D-=20 Rainer M. Krug email: Rainerkrugsde PGP: 0x0F52F982 --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG/MacGPG2 v2.0.22 (Darwin) iQEcBAEBAgAGBQJUq8DdAAoJENvXNx4PUvmCmUUIAIxe/9yrfxPIGaTkx6W2Zbfj oOGktEbZjtUEnWt5WVQWIDba1E9j8p752nvRjBhX7FXvaVBrXv2raduZ1Sy7r8f0 5M20vQaoFIQAtd2n23Ui0vD/3Avb+oA/54IB8t7KS5jzpSuuN5Grart2UpdG8GDr sh4Ux7+pD9pARBWTHkRLWzEfCbd2U3GCpoUIJlYpj2S/h/ZJ5UZfQdj462pxb+3q 38M8yTB9iFO4JaMidliPd1QfLLDEamV/63HUHuRDHPmMTv5N4Wxk+1kecvr/o+PY BVUVrsmIsQxPMoSxBSZXyUqQUYKglNqH+Je04KBYcj5sjjv1pV4/L1OWP7r3n7k= =XrSh -----END PGP SIGNATURE----- --=-=-=--