Re: [O] [patch] [babel] Patches to fix tangling and variable transfer of tables in R

2014-07-29 Thread Rainer M Krug
Bastien b...@gnu.org writes:

 Hi Rainer,

 Rainer M Krug rai...@krugs.de writes:

 Amended patches attached.

 Applied, thanks,

Thanks,

Rainer

-- 
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:  rai...@krugs.de

Skype:  RMkrug

PGP: 0x0F52F982


pgpaSMV6WtrTp.pgp
Description: PGP signature


Re: [O] [patch] [babel] Patches to fix tangling and variable transfer of tables in R

2014-07-28 Thread Bastien
Hi Rainer,

Rainer M Krug rai...@krugs.de writes:

 Amended patches attached.

Applied, thanks,

-- 
 Bastien



Re: [O] [patch] [babel] Patches to fix tangling and variable transfer of tables in R

2014-07-27 Thread Charles Berry
Rainer M Krug Rainer at krugs.de writes:

 
 Nicolas Goaziou mail at nicolasgoaziou.fr writes:
 
  Hello,
 
  Rainer M Krug Rainer at krugs.de writes:
 
[snip]
 
 Amended patches attached.


AFAICS, these patches are good to go. Can they be applied, please?

Chuck






Re: [O] [patch] [babel] Patches to fix tangling and variable transfer of tables in R

2014-07-08 Thread Rainer M Krug
Rainer M Krug rai...@krugs.de writes:

Just to ping these patches for application.

Cheers,

Rainer


 Nicolas Goaziou m...@nicolasgoaziou.fr writes:

 Hello,

 Rainer M Krug rai...@krugs.de writes:

 Attached please find two patches ready for application to fix that table
 variables were not usable adter tangling as temporary files were used.
 These patches were discussed in the thread [babel][PATCHES] ob-R
 patches for review

 I have not much to say about the feature, since I don't use R. Usual
 nitpicking follows.

 +(if (integerp value) (format %s - %s name (concat (number-to-string 
 value) L))
 +  (if (floatp value) (format %s - %s name value)
 +   (if (stringp value) (format %s - %S name value) 
 + (format %s - %S name (prin1-to-string value)))

 I think a `cond' would be more readable here.

 Amended patches attached.



 Regards,

-- 
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:  rai...@krugs.de

Skype:  RMkrug

PGP: 0x0F52F982


pgpUyiBKyFB1K.pgp
Description: PGP signature


Re: [O] [patch] [babel] Patches to fix tangling and variable transfer of tables in R

2014-07-01 Thread Rainer M Krug
Nicolas Goaziou m...@nicolasgoaziou.fr writes:

 Hello,

 Rainer M Krug rai...@krugs.de writes:

 Attached please find two patches ready for application to fix that table
 variables were not usable adter tangling as temporary files were used.
 These patches were discussed in the thread [babel][PATCHES] ob-R
 patches for review

 I have not much to say about the feature, since I don't use R. Usual
 nitpicking follows.

 +(if (integerp value) (format %s - %s name (concat (number-to-string 
 value) L))
 +  (if (floatp value) (format %s - %s name value)
 +(if (stringp value) (format %s - %S name value) 
 +  (format %s - %S name (prin1-to-string value)))

 I think a `cond' would be more readable here.

Agreed - my emacs lisp knowledge is growing daily...

Will send the revised patch later,

Rainer



 Regards,

-- 
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:  rai...@krugs.de

Skype:  RMkrug

PGP: 0x0F52F982


pgpYisJfteTnT.pgp
Description: PGP signature


Re: [O] [patch] [babel] Patches to fix tangling and variable transfer of tables in R

2014-07-01 Thread Rainer M Krug
Nicolas Goaziou m...@nicolasgoaziou.fr writes:

 Hello,

 Rainer M Krug rai...@krugs.de writes:

 Attached please find two patches ready for application to fix that table
 variables were not usable adter tangling as temporary files were used.
 These patches were discussed in the thread [babel][PATCHES] ob-R
 patches for review

 I have not much to say about the feature, since I don't use R. Usual
 nitpicking follows.

 +(if (integerp value) (format %s - %s name (concat (number-to-string 
 value) L))
 +  (if (floatp value) (format %s - %s name value)
 +(if (stringp value) (format %s - %S name value) 
 +  (format %s - %S name (prin1-to-string value)))

 I think a `cond' would be more readable here.

Amended patches attached.



 Regards,

-- 
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:  rai...@krugs.de

Skype:  RMkrug

PGP: 0x0F52F982
From 38c029b38c85d9f9d35d0867b332eebc3daf1aca Mon Sep 17 00:00:00 2001
From: Rainer M. Krug r.m.k...@gmail.com
Date: Fri, 20 Jun 2014 22:19:59 +0200
Subject: [PATCH 1/2] lisp/ob-R.el: Fix tangling with tables

* lisp/ob-R.el (org-babel-R-assign-elisp): Fix variable transfer of
tables by using text connections in R instead of files.  Variable
transfer of tables does not depend on files anymore, i.e. works also
when tangling.
---
 lisp/ob-R.el | 52 
 1 file changed, 32 insertions(+), 20 deletions(-)

diff --git a/lisp/ob-R.el b/lisp/ob-R.el
index a3ae1ec..c77a103 100644
--- a/lisp/ob-R.el
+++ b/lisp/ob-R.el
@@ -190,32 +190,44 @@ This function is called by `org-babel-execute-src-block'.
   (if (listp value)
   (let* ((lengths (mapcar 'length (org-remove-if-not 'sequencep value)))
 	 (max (if lengths (apply 'max lengths) 0))
-	 (min (if lengths (apply 'min lengths) 0))
-	 (transition-file (org-babel-temp-file R-import-)))
+	 (min (if lengths (apply 'min lengths) 0)))
 ;; Ensure VALUE has an orgtbl structure (depth of at least 2).
 (unless (listp (car value)) (setq value (list value)))
-(with-temp-file transition-file
-  (insert
-	   (orgtbl-to-tsv value '(:fmt org-babel-R-quote-tsv-field))
-	   \n))
-	(let ((file (org-babel-process-file-name transition-file 'noquote))
+	(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 (= max min)
-	  (format %s - read.table(\%s\,
-  header=%s,
-  row.names=%s,
-  sep=\\\t\,
-  as.is=TRUE) name file header row-names)
-	(format %s - read.table(\%s\,
-   header=%s,
-   row.names=%s,
-   sep=\\\t\,
-   as.is=TRUE,
-   fill=TRUE,
-   col.names = paste(\V\, seq_len(%d), sep =\\))
-		name file header row-names max
+	  (format %s - local({
+con - textConnection(
+  %S
+)
+res - read.table(
+  con,
+  header= %s,
+  row.names = %s,
+  sep   = \\\t\,
+  as.is = TRUE
+)
+close(con)
+res
+}) name file header row-names)
+	(format %s - local({
+   con - textConnection(
+ %S
+   )
+   res - read.table(
+ con,
+ header= %s,
+ row.names = %s,
+ sep   = \\\t\,
+ as.is = TRUE,
+ fill  = TRUE,
+ col.names = paste(\V\, seq_len(%d), sep =\\)
+   )
+   close(con)
+   res
+   }) name file header row-names max
 (format %s - %s name (org-babel-R-quote-tsv-field value
 
 (defvar ess-ask-for-ess-directory) ; dynamically scoped
-- 
2.0.0

From 551d003d15c5cc9d3792909a12247fca58ae8d84 Mon Sep 17 00:00:00 2001
From: Rainer M. Krug r.m.k...@gmail.com
Date: Mon, 23 Jun 2014 12:11:59 +0200
Subject: [PATCH 2/2] Make transfer of values from R type aware

* lisp/ob-R.el (org-babel-R-assign-elisp): Added different cases for
transfer of integer, float, string and other variables to R so that
now integer values are transferred as integers (L) and 

[O] [patch] [babel] Patches to fix tangling and variable transfer of tables in R

2014-06-30 Thread Rainer M Krug

Hi

Attached please find two patches ready for application to fix that table
variables were not usable adter tangling as temporary files were used.
These patches were discussed in the thread [babel][PATCHES] ob-R
patches for review

Thanks,

RainerFrom 38c029b38c85d9f9d35d0867b332eebc3daf1aca Mon Sep 17 00:00:00 2001
From: Rainer M. Krug r.m.k...@gmail.com
Date: Fri, 20 Jun 2014 22:19:59 +0200
Subject: [PATCH 1/2] lisp/ob-R.el: Fix tangling with tables

* lisp/ob-R.el (org-babel-R-assign-elisp): Fix variable transfer of
tables by using text connections in R instead of files.  Variable
transfer of tables does not depend on files anymore, i.e. works also
when tangling.
---
 lisp/ob-R.el | 52 
 1 file changed, 32 insertions(+), 20 deletions(-)

diff --git a/lisp/ob-R.el b/lisp/ob-R.el
index a3ae1ec..c77a103 100644
--- a/lisp/ob-R.el
+++ b/lisp/ob-R.el
@@ -190,32 +190,44 @@ This function is called by `org-babel-execute-src-block'.
   (if (listp value)
   (let* ((lengths (mapcar 'length (org-remove-if-not 'sequencep value)))
 	 (max (if lengths (apply 'max lengths) 0))
-	 (min (if lengths (apply 'min lengths) 0))
-	 (transition-file (org-babel-temp-file R-import-)))
+	 (min (if lengths (apply 'min lengths) 0)))
 ;; Ensure VALUE has an orgtbl structure (depth of at least 2).
 (unless (listp (car value)) (setq value (list value)))
-(with-temp-file transition-file
-  (insert
-	   (orgtbl-to-tsv value '(:fmt org-babel-R-quote-tsv-field))
-	   \n))
-	(let ((file (org-babel-process-file-name transition-file 'noquote))
+	(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 (= max min)
-	  (format %s - read.table(\%s\,
-  header=%s,
-  row.names=%s,
-  sep=\\\t\,
-  as.is=TRUE) name file header row-names)
-	(format %s - read.table(\%s\,
-   header=%s,
-   row.names=%s,
-   sep=\\\t\,
-   as.is=TRUE,
-   fill=TRUE,
-   col.names = paste(\V\, seq_len(%d), sep =\\))
-		name file header row-names max
+	  (format %s - local({
+con - textConnection(
+  %S
+)
+res - read.table(
+  con,
+  header= %s,
+  row.names = %s,
+  sep   = \\\t\,
+  as.is = TRUE
+)
+close(con)
+res
+}) name file header row-names)
+	(format %s - local({
+   con - textConnection(
+ %S
+   )
+   res - read.table(
+ con,
+ header= %s,
+ row.names = %s,
+ sep   = \\\t\,
+ as.is = TRUE,
+ fill  = TRUE,
+ col.names = paste(\V\, seq_len(%d), sep =\\)
+   )
+   close(con)
+   res
+   }) name file header row-names max
 (format %s - %s name (org-babel-R-quote-tsv-field value
 
 (defvar ess-ask-for-ess-directory) ; dynamically scoped
-- 
2.0.0

From e62a75e7227027c406d23fa9f8ac594db2ce81d6 Mon Sep 17 00:00:00 2001
From: Rainer M. Krug r.m.k...@gmail.com
Date: Mon, 23 Jun 2014 12:11:59 +0200
Subject: [PATCH 2/2] Make transfer of values from R type aware

* lisp/ob-R.el (org-babel-R-assign-elisp): Added different cases for
transfer of integer, float, string and other variables to R so that
now integer values are transferred as integers (L) and stored in R as
such.  This change is backward compatible as integer values are
numerical values in R.
Moved definition of R functions for transfer of tables into defconst
ob-R-transfer-variable-table-with-header and
ob-R-transfer-variable-table-without-header.
---
 lisp/ob-R.el | 78 
 1 file changed, 47 insertions(+), 31 deletions(-)

diff --git a/lisp/ob-R.el b/lisp/ob-R.el
index c77a103..92c1dbc 100644
--- a/lisp/ob-R.el
+++ b/lisp/ob-R.el
@@ -93,6 +93,44 @@ this variable.)
 (when (and session (string-match ^\\*\\(.+?\\)\\*$ session))
   (save-match-data (org-babel-R-initiate-session session nil)
 
+(defconst ob-R-transfer-variable-table-with-header
+  %s - local({
+ con - textConnection(
+   %S
+ )
+ res - read.table(
+   con,
+   header= %s,
+   row.names = %s,
+   sep   = \\\t\,
+   as.is  

Re: [O] [patch] [babel] Patches to fix tangling and variable transfer of tables in R

2014-06-30 Thread Nicolas Goaziou
Hello,

Rainer M Krug rai...@krugs.de writes:

 Attached please find two patches ready for application to fix that table
 variables were not usable adter tangling as temporary files were used.
 These patches were discussed in the thread [babel][PATCHES] ob-R
 patches for review

I have not much to say about the feature, since I don't use R. Usual
nitpicking follows.

 +(if (integerp value) (format %s - %s name (concat (number-to-string 
 value) L))
 +  (if (floatp value) (format %s - %s name value)
 + (if (stringp value) (format %s - %S name value) 
 +   (format %s - %S name (prin1-to-string value)))

I think a `cond' would be more readable here.


Regards,

-- 
Nicolas Goaziou