From mboxrd@z Thu Jan 1 00:00:00 1970 From: tsd@tsdye.com (Thomas S. Dye) Subject: Re: Babel: communicating irregular data to R source-code block Date: Mon, 23 Apr 2012 20:44:55 -1000 Message-ID: References: <1335039472.9075.YahooMailNeo@web161901.mail.bf1.yahoo.com> <87ipgrn4by.fsf@gmx.com> <1335219898.41851.YahooMailNeo@web161901.mail.bf1.yahoo.com> <87aa22t5vn.fsf@gmx.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([208.118.235.92]:48983) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SMZUy-0003ns-PI for emacs-orgmode@gnu.org; Tue, 24 Apr 2012 02:45:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SMZUt-0005Ql-I1 for emacs-orgmode@gnu.org; Tue, 24 Apr 2012 02:45:16 -0400 Received: from oproxy7-pub.bluehost.com ([67.222.55.9]:40118) by eggs.gnu.org with smtp (Exim 4.71) (envelope-from ) id 1SMZUt-0005MV-91 for emacs-orgmode@gnu.org; Tue, 24 Apr 2012 02:45:11 -0400 In-Reply-To: <87aa22t5vn.fsf@gmx.com> (Eric Schulte's message of "Mon, 23 Apr 2012 18:55:56 -0400") 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: Eric Schulte Cc: Michael Hannon , Org-Mode List Eric Schulte writes: >> If I add fill=3DTRUE to that (on a git branch), then I get this: >> >> #+RESULTS: pascals-triangle >> | 1 | | | | | | >> | 1 | 1 | | | | | >> | 1 | 2 | 1 | | | | >> | 1 | 3 | 3 | 1 | | | >> | 1 | 4 | 6 | 4 | 1 | | >> | 1 | 5 | 10 | 10 | 5 | 1 | >> >> #+NAME: sanity-check >> #+HEADER: :var sc_input=3Dpascals-triangle >> #+BEGIN_SRC R >> sc_input >> #+END_SRC >> #+RESULTS: sanity-check >> >> | 1 | nil | nil | nil | nil | >> | 1 | 1 | nil | nil | nil | >> | 1 | 2 | 1 | nil | nil | >> | 1 | 3 | 3 | 1 | nil | >> | 1 | 4 | 6 | 4 | 1 | >> | 1 | 5 | 10 | 10 | 5 | >> | 1 | nil | nil | nil | nil | >> >> which isn't correct, but gets past the scan error. >> > > Hmm, this happens with my patch applied as well. It seems to me this > *must* be an R error. The raw textual data pre-import has no such wrap. > > 1 > 1 1 > 1 2 1 > 1 3 3 1 > 1 4 6 4 1 > 1 5 10 10 5 1 > > Why would R intentionally wrap a table at an arbitrary column? > >> >> I'm in over my head here, but hope that my curiosity hasn't been too >> noisy. >> > > Me too. Unless someone who is familiar with the motivations and design > decisions behind R's read.table function, I'm inclined to leave the > current Org-mode code as is. > > Thanks, The documentation of read.table has this: The number of data columns is determined by looking at the first five lines of input (or the whole file if it has less than five lines), or from the length of col.names if it is specified and is longer. This could conceivably be wrong if fill or blank.lines.skip are true, so specify col.names if necessary (as in the =E2=80=98Examples=E2=80=99). The example is this: read.csv(tf, fill =3D TRUE, header =3D FALSE, col.names =3D paste("V", seq_len(ncol), sep =3D "")) where read.csv is a synonym of read.table with preset arguments. This explains why the sixth line wraps. Unfortunately, ncol passed to seq_len doesn't cooperate. I can hard code the read.table call this way: (format "%s <- read.table(\"%s\", header=3D%s, row.names=3D%s, sep= =3D\"\\t\", as.is=3DTRUE, fill=3DTRUE, col.names =3D paste(\"V\", seq_len(6= ), sep =3D \"\"))" This works for the example with six columns: #+RESULTS: pascals-triangle | 1 | | | | | | | 1 | 1 | | | | | | 1 | 2 | 1 | | | | | 1 | 3 | 3 | 1 | | | | 1 | 4 | 6 | 4 | 1 | | | 1 | 5 | 10 | 10 | 5 | 1 | #+NAME: sanity-check #+HEADER: :var sc_input=3Dpascals-triangle #+BEGIN_SRC R sc_input #+END_SRC #+RESULTS: sanity-check | 1 | nil | nil | nil | nil | nil | | 1 | 1 | nil | nil | nil | nil | | 1 | 2 | 1 | nil | nil | nil | | 1 | 3 | 3 | 1 | nil | nil | | 1 | 4 | 6 | 4 | 1 | nil | | 1 | 5 | 10 | 10 | 5 | 1 | I think that seq_len(%s) passed the number of columns in the orgtbl-tsv table might do the trick, but I don't know how to do this, or if this information is available. I also don't have any idea what these changes might do to regular tables. All the best, Tom =20 --=20 Thomas S. Dye http://www.tsdye.com