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: Mon, 23 Jun 2014 11:14:59 +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]:55813) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wz0LP-000686-FE for emacs-orgmode@gnu.org; Mon, 23 Jun 2014 05:15:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Wz0LJ-0006fJ-V8 for emacs-orgmode@gnu.org; Mon, 23 Jun 2014 05:15:19 -0400 Received: from mail-wi0-f170.google.com ([209.85.212.170]:40167) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wz0LJ-0006fF-La for emacs-orgmode@gnu.org; Mon, 23 Jun 2014 05:15:13 -0400 Received: by mail-wi0-f170.google.com with SMTP id cc10so3825947wib.3 for ; Mon, 23 Jun 2014 02:15:09 -0700 (PDT) In-Reply-To: (Charles C. Berry's message of "Sat, 21 Jun 2014 12:44:01 -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 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 passed as =3Dcolnames=3D while 2. routine: =3Dheader=3D is not present (FALSE) and =3Dcolnames=3D is gener= ated 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 second routine. From R: ,---- | fill: logical. If =E2=80=98TRUE=E2=80=99 then in case the rows have u= nequal 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? Cheers, Rainer "Charles C. Berry" writes: > On Fri, 20 Jun 2014, Rainer M Krug wrote: > >> Attached please find =3Dthe reworked patch. >> >> 1) uses local() and closes connection >> 2) does not leave a variable cal;led file behind >> > > Seems to work on a few test cases. > > I'd move the strings to defconsts. > > Putting a newline before each `%S' will outdent the first line of=20 > :var value when it is echoed in the session log so it will be easier to=20 > view. > > =3D=3D=3D > > With Eric's input on this: > > Would you also change this at the end of org-babel-R-assign-elisp: > > res})" name file header row-names max)))) > - (format "%s <- %s" name (org-babel-R-quote-tsv-field value)))) > + (format "%s <- %S" name > + (if (stringp value) value (prin1-to-string value))))) > > ?? > > I think this is innocuous for plain strings with no internal quotes, but= =20 > allows almost anything to be passed to R as a string. > > So > :var x=3D[1 2 3 "4" 5] > > will be passed to R as x <- "[1 2 3 \"4\" 5]" > > instead of x <- "[1 2 3 "4" 5] which throws an error. > > And this just works: > > #+NAME: latex-capt > #+BEGIN_SRC latex > \begin{math} > y =3D X\beta, > \mbox{where } \beta =3D %beta% > \end{math} > #+END_SRC > > #+BEGIN_SRC R :var ytxt=3Dlatex-capt :results raw :wrap latex > beta <- 1.234 > sub("%beta%",beta,ytxt) > #+END_SRC > > > HTH, > > Chuck =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) iQEcBAEBAgAGBQJTp/AZAAoJENvXNx4PUvmCXLUIALZ4NgNZ5DlhPXMn5u/Uz7DR I1pZSaP65jBrg379BEUgxIC8/MT+UeZjW9I8w9L1gwgo5ycy4PGTTYXOJNImhFC3 T+RPG1r2Fkn638Gq3kb3Z+JwIqKPm3JyIWdW30E2YQsq+0XdsH/RpE/9UJ6mEZS6 qGMqmUA3yfw3djioCFozwXT5iXwYLUxRDRNpVZnouovKWai72aioc6HUsmKr5bmi imnW8n2dIvnk95+xU16wN76WQgqAJOs1Nn9h1MiWCGqHWEraM5KfH5+vMfvlFYrG 13stXu5kIE6nCqMVdgI+V1YEHAEMnVPWSZSl+ac0/+TkWeaqZuEZnz6lTmmv0I0= =s9vZ -----END PGP SIGNATURE----- --=-=-=--