From mboxrd@z Thu Jan 1 00:00:00 1970 From: Michael Hannon Subject: Re: Babel: communicating irregular data to R source-code block Date: Mon, 23 Apr 2012 15:24:58 -0700 (PDT) Message-ID: <1335219898.41851.YahooMailNeo@web161901.mail.bf1.yahoo.com> References: <1335039472.9075.YahooMailNeo@web161901.mail.bf1.yahoo.com> <87ipgrn4by.fsf@gmx.com> Reply-To: Michael Hannon Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([208.118.235.92]:42930) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SMRgt-0001AE-8q for emacs-orgmode@gnu.org; Mon, 23 Apr 2012 18:25:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SMRgr-0005oK-6j for emacs-orgmode@gnu.org; Mon, 23 Apr 2012 18:25:02 -0400 Received: from nm15.bullet.mail.bf1.yahoo.com ([98.139.212.174]:43003) by eggs.gnu.org with smtp (Exim 4.71) (envelope-from ) id 1SMRgq-0005ng-ST for emacs-orgmode@gnu.org; Mon, 23 Apr 2012 18:25:01 -0400 In-Reply-To: <87ipgrn4by.fsf@gmx.com> 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 , "Thomas S. Dye" Cc: Org-Mode List Greetings.=A0 I'm sorry to belabor this, but I thought I had found a relati= vely=0Aclean way to pass a "ragged" table to an R source-code block.=A0 Sim= ple answer:=0Aadd the "fill=3DTRUE" option to the read.table function.=A0 P= lease see the=0Aappended for the log of an R session that does what I want.= =0A=0AI then tried to do the same thing in an R source-code block:=0A=0A=A0= =A0=A0 #+RESULTS: pascals_triangle=0A=A0=A0=A0 | 1 |=A0=A0 |=A0=A0=A0 |=A0= =A0=A0 |=A0=A0 |=A0=A0 |=0A=A0=A0=A0 | 1 | 1 |=A0=A0=A0 |=A0=A0=A0 |=A0=A0 = |=A0=A0 |=0A=A0=A0=A0 | 1 | 2 |=A0 1 |=A0=A0=A0 |=A0=A0 |=A0=A0 |=0A=A0=A0= =A0 | 1 | 3 |=A0 3 |=A0 1 |=A0=A0 |=A0=A0 |=0A=A0=A0=A0 | 1 | 4 |=A0 6 |=A0= 4 | 1 |=A0=A0 |=0A=A0=A0=A0 | 1 | 5 | 10 | 10 | 5 | 1 |=0A=A0=A0 =A0=0A=A0= =A0 =A0=0A=A0=A0=A0 #+NAME: sanity-check(sc_input=3Dpascals_triangle)=0A=A0= =A0=A0 #+BEGIN_SRC R=0A=A0=A0 =A0=0A=A0=A0=A0 pt <- read.table(sc_input, fi= ll=3DTRUE)=0A=A0=A0=A0 rowSums(pt)=0A=A0=A0 =A0=0A=A0=A0=A0 #+END_SRC =A0= =0A=0AUnfortunately, this still results in the "error" that the first line = did not=0Acontain five elements:=0A=0A<<<<<<<<<<=0A> Error in scan(file, wh= at, nmax, sep, dec, quote, skip, nlines, na.strings,=0A> : =0A=A0 line 1 di= d not have 5 elements=0A=0AEnter a frame number, or 0 to exit=A0 =A0=0A=0A1= : read.table("/tmp/babel-3780tje/R-import-37801if", header =3D FALSE, row.n= ames=0A=3D NULL, sep =3D "=0A2: scan(file =3D file, what =3D what, sep =3D = sep, quote =3D quote, dec =3D dec, nmax =3D=0Anrows, skip =3D 0,=0A>>>>>>>>= >>=0A=0AI.e.,it seems that Org is going to do its own "read.table" before e= ven=0Alooking at the code in the source block.=0A=0AIs there some way to ge= t Org to use the "fill=3DTRUE" option on a case-by-case=0Abasis?=0A=0AThank= s.=0A=0A-- Mike=0A=0A=0AAppendix: R code that correctly reads and processes= a Pascal's triangle=0A=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D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