summaryrefslogtreecommitdiff
path: root/lisp/org/ob-R.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/org/ob-R.el')
-rw-r--r--lisp/org/ob-R.el39
1 files changed, 26 insertions, 13 deletions
diff --git a/lisp/org/ob-R.el b/lisp/org/ob-R.el
index 2b0e6d5e16a..e8400f494ad 100644
--- a/lisp/org/ob-R.el
+++ b/lisp/org/ob-R.el
@@ -1,12 +1,11 @@
;;; ob-R.el --- org-babel functions for R code evaluation
-;; Copyright (C) 2009-2011 Free Software Foundation, Inc.
+;; Copyright (C) 2009-2012 Free Software Foundation, Inc.
;; Author: Eric Schulte
;; Dan Davison
;; Keywords: literate programming, reproducible research, R, statistics
;; Homepage: http://orgmode.org
-;; Version: 7.7
;; This file is part of GNU Emacs.
@@ -80,7 +79,8 @@
"Execute a block of R code.
This function is called by `org-babel-execute-src-block'."
(save-excursion
- (let* ((result-type (cdr (assoc :result-type params)))
+ (let* ((result-params (cdr (assoc :result-params params)))
+ (result-type (cdr (assoc :result-type params)))
(session (org-babel-R-initiate-session
(cdr (assoc :session params)) params))
(colnames-p (cdr (assoc :colnames params)))
@@ -89,7 +89,7 @@ This function is called by `org-babel-execute-src-block'."
(full-body (org-babel-expand-body:R body params graphics-file))
(result
(org-babel-R-evaluate
- session full-body result-type
+ session full-body result-type result-params
(or (equal "yes" colnames-p)
(org-babel-pick-name
(cdr (assoc :colname-names params)) colnames-p))
@@ -197,6 +197,7 @@ current code buffer."
'((:bmp . "bmp")
(:jpg . "jpeg")
(:jpeg . "jpeg")
+ (:tex . "tikz")
(:tiff . "tiff")
(:png . "png")
(:svg . "svg")
@@ -214,7 +215,7 @@ current code buffer."
(setq device (or (and device (cdr (assq (intern (concat ":" device))
devices))) "png"))
(setq filearg
- (if (member device '("pdf" "postscript" "svg")) "file" "filename"))
+ (if (member device '("pdf" "postscript" "svg" "tikz")) "file" "filename"))
(setq args (mapconcat
(lambda (pair)
(if (member (car pair) allowed-args)
@@ -232,16 +233,16 @@ current code buffer."
(defvar org-babel-R-write-object-command "{function(object,transfer.file){object;invisible(if(inherits(try({tfile<-tempfile();write.table(object,file=tfile,sep=\"\\t\",na=\"nil\",row.names=%s,col.names=%s,quote=FALSE);file.rename(tfile,transfer.file)},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)
+ (session body result-type result-params column-names-p row-names-p)
"Evaluate R code in BODY."
(if session
(org-babel-R-evaluate-session
- session body result-type column-names-p row-names-p)
+ session body result-type result-params column-names-p row-names-p)
(org-babel-R-evaluate-external-process
- body result-type column-names-p row-names-p)))
+ body result-type result-params column-names-p row-names-p)))
(defun org-babel-R-evaluate-external-process
- (body result-type column-names-p row-names-p)
+ (body result-type result-params column-names-p row-names-p)
"Evaluate BODY in external R process.
If RESULT-TYPE equals 'output then return standard output as a
string. If RESULT-TYPE equals 'value then return the value of the
@@ -258,11 +259,17 @@ last statement in BODY, as elisp."
(format "{function ()\n{\n%s\n}}()" body)
(org-babel-process-file-name tmp-file 'noquote)))
(org-babel-R-process-value-result
- (org-babel-import-elisp-from-file tmp-file '(16)) column-names-p)))
+ (if (or (member "scalar" result-params)
+ (member "verbatim" result-params))
+ (with-temp-buffer
+ (insert-file-contents tmp-file)
+ (buffer-string))
+ (org-babel-import-elisp-from-file tmp-file '(16)))
+ column-names-p)))
(output (org-babel-eval org-babel-R-command body))))
(defun org-babel-R-evaluate-session
- (session body result-type column-names-p row-names-p)
+ (session body result-type result-params column-names-p row-names-p)
"Evaluate BODY in SESSION.
If RESULT-TYPE equals 'output then return standard output as a
string. If RESULT-TYPE equals 'value then return the value of the
@@ -284,7 +291,13 @@ last statement in BODY, as elisp."
"FALSE")
".Last.value" (org-babel-process-file-name tmp-file 'noquote)))
(org-babel-R-process-value-result
- (org-babel-import-elisp-from-file tmp-file '(16)) column-names-p)))
+ (if (or (member "scalar" result-params)
+ (member "verbatim" result-params))
+ (with-temp-buffer
+ (insert-file-contents tmp-file)
+ (buffer-string))
+ (org-babel-import-elisp-from-file tmp-file '(16)))
+ column-names-p)))
(output
(mapconcat
#'org-babel-chomp
@@ -295,7 +308,7 @@ last statement in BODY, as elisp."
(mapcar
(lambda (line) ;; cleanup extra prompts left in output
(if (string-match
- "^\\([ ]*[>+][ ]?\\)+\\([[0-9]+\\|[ ]\\)" line)
+ "^\\([ ]*[>+\\.][ ]?\\)+\\([[0-9]+\\|[ ]\\)" line)
(substring line (match-end 1))
line))
(org-babel-comint-with-output (session org-babel-R-eoe-output)