From mboxrd@z Thu Jan 1 00:00:00 1970 From: Rainer M Krug Subject: Re: [PATCH] -for review- Tangling with variable transfer of variables Date: Tue, 24 Jun 2014 14:08:36 +0200 Message-ID: References: <87zjh8bo8s.fsf@gmail.com> 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]:42819) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WzPWs-0007oP-NS for emacs-orgmode@gnu.org; Tue, 24 Jun 2014 08:08:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WzPWn-0003UB-2y for emacs-orgmode@gnu.org; Tue, 24 Jun 2014 08:08:50 -0400 Received: from mail-we0-f170.google.com ([74.125.82.170]:56192) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WzPWm-0003U7-RV for emacs-orgmode@gnu.org; Tue, 24 Jun 2014 08:08:45 -0400 Received: by mail-we0-f170.google.com with SMTP id w61so237794wes.1 for ; Tue, 24 Jun 2014 05:08:40 -0700 (PDT) In-Reply-To: (Charles C. Berry's message of "Mon, 23 Jun 2014 10:56:05 -0700") 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: "Charles C. Berry" Cc: emacs-orgmode@gnu.org, Eric Schulte --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable "Charles C. Berry" writes: > On Mon, 23 Jun 2014, Rainer M Krug wrote: > >> One more question concerning the variable transfer of tables: >> >> ,---- >> | (let ((file (orgtbl-to-tsv value '(:fmt org-babel-R-quote-tsv-field))) >> | (header (if (or (eq (nth 1 value) 'hline) colnames-p) >> | "TRUE" "FALSE")) >> | (row-names (if rownames-p "1" "NULL"))) >> | (if (=3D max min) >> | (format "%s <- local({ >> | con <- textConnection( >> | %S >> | ) >> | res <- read.table( >> | con, >> | header =3D %s, >> | row.names =3D %s, >> | sep =3D \"\\t\", >> | as.is =3D TRUE >> | ) >> | close(con) >> | res >> | })" name file header row-names) >> | (format "%s <- local({ >> | con <- textConnection( >> | %S >> | ) >> | res <- read.table( >> | con, >> | header =3D %s, >> | row.names =3D %s, >> | sep =3D \"\\t\", >> | as.is =3D TRUE, >> | fill =3D TRUE, >> | col.names =3D paste(\"V\", seq_len(%d), sep = =3D\"\") >> | ) >> | close(con) >> | res >> | })" name file header row-names max)))) >> `---- >> >> It seems that the two variable transfer routines only differ slightly: >> >> 1. routine: =3Dheader=3D is present (TRUE) and defined in table when pas= sed >> as =3Dcolnames=3D while >> >> 2. routine: =3Dheader=3D is not present (FALSE) and =3Dcolnames=3D is ge= nerated >> as V1 .. Vn >> >> This generation is actually not needed as this is the R default value >> which is used when =3Dcolnames=3D is not supplied. >> >> Also: I do not undestand why the argument =3Dfill=3D is TRUE in the seco= nd >> routine. From R: >> >> ,---- >> | fill: logical. If =E2=80=98TRUE=E2=80=99 then in case the rows hav= e unequal length, >> | blank fields are implicitly added. See =E2=80=98Details=E2= =80=99. >> `---- >> >> If I understands tables in org correctly, this is not needed as the rows >> always have equal length? >> >> so if I am not mistaken the following lines could be deleted: >> >> ,---- >> | row.names =3D %s, >> | sep =3D \"\\t\", >> | as.is =3D TRUE, >> | - fill =3D TRUE, >> | - col.names =3D paste(\"V\", seq_len(%d), sep= =3D\"\") >> `---- >> >> Or am I missing something here? > > You need not pass a table - this > > #+BEGIN_SRC R :var x=3D'(1 2 3)(4 5)) I always forget that there are other objects wich can be passed from org to R. > > will produce a data.frame with two rows with is.na(x[2,2]) being TRUE. > > > Re col.names, from help("read.table") > > 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 'Examples'). > > > This block > > #+BEGIN_SRC R :var x=3D(append (make-vector 10 '(1 2)) '((1 2 3))) > x > #+END_SRC > > makes an 11 by 3 data.frame with all(is.na(x[,1:10])) > > but taking away the col.names arg will cause it to make a 12 by 2=20 > data.frame with x[12,1]=3D=3D3 and is.na(x[12,2]). > > so leave the col.names as is, I think. I will - promised. =20 > > Without fill, read.table will throw an error in that block This is true for these cases - I was only thinking about tables which can be passed to R Thanks, Rainer > > Chuck > > [rest deleted] > =2D-=20 Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation Biology,= UCT), Dipl. Phys. (Germany) Centre of Excellence for Invasion Biology Stellenbosch University South Africa Tel : +33 - (0)9 53 10 27 44 Cell: +33 - (0)6 85 62 59 98 Fax : +33 - (0)9 58 10 27 44 Fax (D): +49 - (0)3 21 21 25 22 44 email: Rainer@krugs.de Skype: RMkrug PGP: 0x0F52F982 --=-=-= Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG/MacGPG2 v2.0.22 (Darwin) iQEcBAEBAgAGBQJTqWpEAAoJENvXNx4PUvmCL70H/jyP0J4HyeSkLfYn1IT1xgs/ 2lINaW2oBAS6QfpLCPO/pWlnCga8GmC21ASOjiORgsF3dajE8R+PtpsDWJIivOct 7T66gFehDiWNYFgwsdAN4lfe9bsnfB/q+prHVadG4GYXv0uoicnEhkO6wSahr3+8 ub7/W8ngL3/QpRQyWOY6FmGA6yH2k1D625/HmaeRUcExLB6QhGLqzbG+JKuMMwhe +j5lJp0OlPqpWWiVckk2qNSxlDWdDD1/MIzhDXnRxdE5ex5F5P5KN0Cx+vt5xmtB rv7/t9S+65n+dwlNpZ+sjMDgtuVynFYIcekxYYwYGqK7QDS/ocqFGDW90TqQDmw= =eTlk -----END PGP SIGNATURE----- --=-=-=--