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: Tue, 24 Apr 2012 09:23:17 -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> <1335251229.83988.YahooMailNeo@web161905.mail.bf1.yahoo.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]:51146) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SMlKk-0002KW-Tp for emacs-orgmode@gnu.org; Tue, 24 Apr 2012 15:23:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SMlKi-000069-TE for emacs-orgmode@gnu.org; Tue, 24 Apr 2012 15:23:30 -0400 Received: from oproxy9.bluehost.com ([69.89.24.6]:46430) by eggs.gnu.org with smtp (Exim 4.71) (envelope-from ) id 1SMlKi-000065-Jf for emacs-orgmode@gnu.org; Tue, 24 Apr 2012 15:23:28 -0400 In-Reply-To: (Thomas S. Dye's message of "Tue, 24 Apr 2012 07:18:19 -1000") 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: Michael Hannon Cc: Org-Mode List , Eric Schulte tsd@tsdye.com (Thomas S. Dye) writes: > Michael Hannon writes: > >> On Monday, April 23, 2012 at 11:44 PM Thomas S. Dye wrote: >> . >> . >> . >>> The documentation of read.table has this: >> >>> The number of data columns is determined by looking at the first five l= ines >>> 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 concei= vably >>> 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, >>>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 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. >> . >> . >> . >> >> Thanks, Tom.=C2=A0 I had just run across this myself. I guess I need to = walk a mile >> in somebody's moccasins before complaining, but this behavior on the par= t of R >> seems totally stupid to me. >> >> I'm going to have to mull this over some more. >> >> -- Mike >> >> > Yes, please do. I'm not a programmer, and often get things wrong, but I > trust you'll help rein me in if I get off on a tangent.=20 > > It would be good if this limitation in ob-R were eliminated. The way I > see it, ob-R is designed to handle a subset of the expected input. It > coerces a variable into a tsv table, then reads it into R, expecting all > cells are filled. At the same time, other babel modules are free to > export structures (in the Pascal's triangle example, a list of lists) > that orgtbl-to-tsv interprets as a table with empty cells. It would be > nice if ob-R could be made to read all the tables that orgtbl-to-tsv is > able to create. > > All the best, > Tom=20 Here is about as far as I can go with this. It appears to work for tables with or without column heads. The 6 is still hard-coded. I can't find a way to determine the number of columns in VALUE, but assume there is one. If the number of columns in VALUE were to replace the hard-coded 6, this might work. (format "%s <- read.table(\"%s\", header=3D%s, row.names=3D%s, sep= =3D\"\\t\", as.is=3DTRUE, fill=3DTRUE%s)" name (org-babel-process-file-name transition-file 'noquote) (if (or (eq (nth 1 value) 'hline) colnames-p) "TRUE" "FALSE") (if rownames-p "1" "NULL") (if (eq (nth 1 value) 'hline) "" ", col.names =3D paste(\"V\", seq_len(6)= , sep =3D \"\")"))) All the best, Tom --=20 Thomas S. Dye http://www.tsdye.com