From mboxrd@z Thu Jan 1 00:00:00 1970 From: Rainer M Krug Subject: Re: [NEW PATCH] read.table in variable transfer caused sometimes "function not found" error - small change Date: Thu, 09 Oct 2014 10:25:01 +0200 Message-ID: References: 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]:38123) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xc929-0004YE-Da for emacs-orgmode@gnu.org; Thu, 09 Oct 2014 04:25:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Xc921-0007gY-Uz for emacs-orgmode@gnu.org; Thu, 09 Oct 2014 04:25:13 -0400 Received: from mail-wg0-f45.google.com ([74.125.82.45]:45130) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xc921-0007cf-M8 for emacs-orgmode@gnu.org; Thu, 09 Oct 2014 04:25:05 -0400 Received: by mail-wg0-f45.google.com with SMTP id m15so695112wgh.16 for ; Thu, 09 Oct 2014 01:25:05 -0700 (PDT) In-Reply-To: (Rainer M. Krug's message of "Thu, 09 Oct 2014 10:19:48 +0200") 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 --==-=-= Content-Type: multipart/mixed; boundary="=-=-=" --=-=-= Content-Type: text/plain *Please ignore the previous patch* This updated patch contains the correct documentation and commit message Sorry about the mistake, --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-ob-R.el-Add-package-name-to-read.table-call.patch Content-Transfer-Encoding: quoted-printable Content-Description: The correct patch From=2058cb8521d4d4b620b0c5210a9b7232f99f7c720c Mon Sep 17 00:00:00 2001 From: "Rainer M. Krug" Date: Mon, 6 Oct 2014 13:48:49 +0200 Subject: [PATCH] ob-R.el: Add package name to read.table call * lisp/ob-R.el: (ob-R-transfer-variable-table-with-header): Add package name to call of R function read.table (now utils::read.table). This clarifies the call as well as avoids 'could not find function' error in R under certain conditions. (ob-R-transfer-variable-table-without-header): Add package name to call of R function read.table (now utils::read.table). This clarifies the call as well as avoids 'could not find function' error in R under certain conditions. =2D-- lisp/ob-R.el | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lisp/ob-R.el b/lisp/ob-R.el index ea33031..0b24a64 100644 =2D-- a/lisp/ob-R.el +++ b/lisp/ob-R.el @@ -101,7 +101,7 @@ this variable.") con <- textConnection( %S ) =2D res <- read.table( + res <- utils::read.table( con, header =3D %s, row.names =3D %s, @@ -112,14 +112,17 @@ this variable.") res })" "R code used to transfer a table defined as a variable from org to R. =2DThis function is used when the table contains a header.") +This function is used when the table contains a header. The usage +of utils::read.table() ensures that the command read.table() can +be found even in circumstances when the utils package is not in +the search path from R.") =20 (defconst ob-R-transfer-variable-table-without-header "%s <- local({ con <- textConnection( %S ) =2D res <- read.table( + res <- utils::read.table( con, header =3D %s, row.names =3D %s, @@ -132,7 +135,10 @@ This function is used when the table contains a header= .") res })" "R code used to transfer a table defined as a variable from org to R. =2DThis function is used when the table does not contain a header.") +This function is used when the table does not contain a +header. The usage of utils::read.table() ensures that the command +read.table() can be found even in circumstances when the utils +package is not in the search path from R.") =20 (defun org-babel-expand-body:R (body params &optional graphics-file) "Expand BODY according to PARAMS, return the expanded body." =2D-=20 2.1.2 --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Rainer Rainer M Krug writes: > "Charles C. Berry" writes: > >> On Wed, 8 Oct 2014, Rainer M Krug wrote: >> >>> "Charles C. Berry" writes: >>> >>>> On Wed, 8 Oct 2014, Rainer M Krug wrote: >>>> >>>>> "Charles C. Berry" writes: >>>>> >>>>>> On Mon, 6 Oct 2014, Rainer M Krug wrote: >>>>>> >>>>>>> Hi >>>>>>> >>>>>>> The variable transfer of tables from org to R caused sometimes 'cou= ld >>>>>>> not find function "read.table"' errors (e.g. when the file was tang= led >>>>>>> into a ./data directory which was loaded by the function >>>>>>> devtools::load_all("./")). This can easily be fixed by adding the p= ackage >>>>>>> name to the call in R, i.e. replacing =3Dread.table()=3D with >>>>>>> =3Dutils::read.table()=3D which is done in this patch. >>>>>> >>>>>> It does fix that one case. >>>>>> >>>>>> But I wonder if that is the best way. >>>>>> >>>>>> The heart of the matter is that load_all eventually calls sys.source, >>>>>> which can be persnickety about finding objects on the search path. S= ee >>>>>> ?sys.source. >>>>>> >>>>>> If the src block you tangle to ./data/ has any code that uses any >>>>>> other objects from utils, stats, datasets or whatever, you will be in >>>>>> the same pickle. >>>>> >>>>> Exactly - that is true. But it is the same when putting this in a >>>>> package (as far as I am aware). >>>>> >>>> >>>> Do you mean that putting `x <- rnorm(10)' into a data/*.R file will >>>> fail when you try to build and check? >>>> >>>> In fact, `R CMD build' will execute it and save the result as a >>>> data/*.rda file. And check will go through. >>>> >>>> devtools::load_all (calling load_data) fails to do that. Which is why >>>> I think this is a devtools issue. >>> >>> OK - point taken. But I still think that the =3Dutils::read.table()=3D = would >>> not hurt, rather make the variable transfer safer. >>> >> >> What you want to change is in a defconst. So, the user can override >> with a file-local version. >> >> So, making the change really is harmless. >> >> Maybe add a note to the docstring to say that using >> utils::read.table' assures that `read.table' always can be found just >> in case anyone ever asks. > > OK - done in attached patch. > > Rainer > From 1eadbf6b44b8fc2fa5af29ea483383e9d137d19e Mon Sep 17 00:00:00 2001 > From: "Rainer M. Krug" > Date: Mon, 6 Oct 2014 13:48:49 +0200 > Subject: [PATCH] ob-R.el: Add package name to read.table call > > * lisp/ob-R.el: > (ob-R-transfer-variable-table-with-header): Add package name to call > of R function read.table (now utils::read.table). This clarifies the > call as well as avoids 'could not find function' error in R under > certain conditions. > --- > lisp/ob-R.el | 9 ++++++--- > 1 file changed, 6 insertions(+), 3 deletions(-) > > diff --git a/lisp/ob-R.el b/lisp/ob-R.el > index ea33031..a64b647 100644 > --- a/lisp/ob-R.el > +++ b/lisp/ob-R.el > @@ -101,7 +101,7 @@ this variable.") > con <- textConnection( > %S > ) > - res <- read.table( > + res <- utils::read.table( > con, > header =3D %s, > row.names =3D %s, > @@ -112,14 +112,17 @@ this variable.") > res > })" > "R code used to transfer a table defined as a variable from org to R. > -This function is used when the table contains a header.") > +This function is used when the table contains a header. The usage > +of utils::read.table() ensures that the command read.table() can > +be found even in circumstances when the utils package is not in > +the search path from R.") >=20=20 > (defconst ob-R-transfer-variable-table-without-header > "%s <- local({ > con <- textConnection( > %S > ) > - res <- read.table( > + res <- utils::read.table( > con, > header =3D %s, > row.names =3D %s, > --=20 > 2.1.2 > > >> >> Chuck >> >> =2D-=20 Rainer M. Krug email: Rainerkrugsde PGP: 0x0F52F982 --=-=-=-- --==-=-= Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG/MacGPG2 v2.0.22 (Darwin) iQEcBAEBAgAGBQJUNkZdAAoJENvXNx4PUvmCvaUIALZzqX0JhBAEjpWMCbRmnsGX vGLgbxelVVfmmoQ8grCDLHWd+n+/tCkb/0fSx7zCH4SNG09GSM535cVD28EbCINT 6flWORCGhPwTNkBC7YIF2+M/tog81TfLhQxUp0DxRF6UoGimNrEjpF/YPBbfKFmq HtX0qTqtg3NMY8pEB6JyaaFkGPhfRrt4W0Kk0i+tXu9TTYLgHxYk2TTYMj0QLsgr +JJoxnd8n4BfI7cphZlC1/WPmhOZMrNcpxV+fqfv1WHHh2b7bOYgofMuPAjxTPyz XhlsIi/tqjb/pe22bZxxIo4B2/VXbmrTwLm34J2ffSkaHhwGPd8S+u45+6BBvjk= =mcR6 -----END PGP SIGNATURE----- --==-=-=--