summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Davison <davison@stats.ox.ac.uk>2010-08-28 08:52:37 -0400
committerDan Davison <davison@stats.ox.ac.uk>2010-08-30 09:35:48 -0700
commitfcfba8d487ffe1c03ede5daa101137a408edeae4 (patch)
tree61778ad2bda55acd67c4c1d84eba07921f34cb76
parent08cdd0557967d69a093b1642a4467e800fe84c4b (diff)
downloadorg-mode-fcfba8d487ffe1c03ede5daa101137a408edeae4.tar.gz
babel: R: Unify R write-to-file expressions
* ob-R.el (org-babel-R-write-object-command): New unified R command for writing results to file (org-babel-R-wrapper-method): Remove variable (org-babel-R-wrapper-lastvar): Remove variable (org-babel-R-evaluate-external-process): Use new R command (org-babel-R-evaluate-session): Use new R command
-rw-r--r--lisp/ob-R.el23
1 files changed, 11 insertions, 12 deletions
diff --git a/lisp/ob-R.el b/lisp/ob-R.el
index e726d03..31312d9 100644
--- a/lisp/ob-R.el
+++ b/lisp/ob-R.el
@@ -217,9 +217,7 @@ current code buffer."
(defvar org-babel-R-eoe-indicator "'org_babel_R_eoe'")
(defvar org-babel-R-eoe-output "[1] \"org_babel_R_eoe\"")
-(defvar org-babel-R-wrapper-method "main <- function ()\n{\n%s\n}
-write.table(main(), file=\"%s\", sep=\"\\t\", na=\"nil\",row.names=%s, col.names=%s, quote=FALSE)")
-(defvar org-babel-R-wrapper-lastvar "write.table(.Last.value, file=\"%s\", sep=\"\\t\", na=\"nil\",row.names=%s, col.names=%s, quote=FALSE)")
+(defvar org-babel-R-write-object-command "{function(object, transfer.file) {invisible(if(inherits(try(write.table(object, file=transfer.file, sep=\"\\t\", na=\"nil\",row.names=%s, col.names=%s, quote=FALSE), silent=TRUE),\"try-error\")) {if(!file.exists(transfer.file)) file.create(transfer.file)})}}(object=%s, transfer.file=\"%s\")")
(defun org-babel-R-evaluate
(session body result-type column-names-p row-names-p)
@@ -240,12 +238,13 @@ last statement in BODY, as elisp."
(value
(let ((tmp-file (org-babel-temp-file "R-results-")))
(org-babel-eval org-babel-R-command
- (format org-babel-R-wrapper-method
- body tmp-file
+ (format org-babel-R-write-object-command
(if row-names-p "TRUE" "FALSE")
(if column-names-p
(if row-names-p "NA" "TRUE")
- "FALSE")))
+ "FALSE")
+ (format "{function ()\n{\n%s\n}}()" body)
+ tmp-file))
(org-babel-R-process-value-result
(org-babel-import-elisp-from-file
(org-babel-maybe-remote-file tmp-file) '(16)) column-names-p)))
@@ -267,12 +266,12 @@ last statement in BODY, as elisp."
(let ((tmp-file (org-babel-temp-file "R-")))
(org-babel-comint-eval-invisibly-and-wait-for-file
session (org-babel-maybe-remote-file tmp-file)
- (format org-babel-R-wrapper-lastvar
- tmp-file
- (if row-names-p "TRUE" "FALSE")
- (if column-names-p
- (if row-names-p "NA" "TRUE")
- "FALSE"))
+ (format org-babel-R-write-object-command
+ (if row-names-p "TRUE" "FALSE")
+ (if column-names-p
+ (if row-names-p "NA" "TRUE")
+ "FALSE")
+ ".Last.value" tmp-file))
(org-babel-R-process-value-result
(org-babel-import-elisp-from-file
(org-babel-maybe-remote-file tmp-file) '(16)) column-names-p)))