diff options
| author | Bastien Guerry | 2012-01-03 18:27:21 +0100 |
|---|---|---|
| committer | Bastien Guerry | 2012-01-03 18:27:21 +0100 |
| commit | e66ba1dfc4cf2e12100191d2c24436c42d097268 (patch) | |
| tree | b50b009e703fe1a9e8cb13cddf7928a97ad6210c /lisp/org/ob-R.el | |
| parent | 88c5c7c8313162b94173fd4333e6062aa07c4d2e (diff) | |
| download | emacs-e66ba1dfc4cf2e12100191d2c24436c42d097268.tar.gz emacs-e66ba1dfc4cf2e12100191d2c24436c42d097268.zip | |
Merge Org 7.8.03
Diffstat (limited to 'lisp/org/ob-R.el')
| -rw-r--r-- | lisp/org/ob-R.el | 37 |
1 files changed, 25 insertions, 12 deletions
diff --git a/lisp/org/ob-R.el b/lisp/org/ob-R.el index 2b0e6d5e16a..d8c3d6bbf5e 100644 --- a/lisp/org/ob-R.el +++ b/lisp/org/ob-R.el | |||
| @@ -6,7 +6,6 @@ | |||
| 6 | ;; Dan Davison | 6 | ;; Dan Davison |
| 7 | ;; Keywords: literate programming, reproducible research, R, statistics | 7 | ;; Keywords: literate programming, reproducible research, R, statistics |
| 8 | ;; Homepage: http://orgmode.org | 8 | ;; Homepage: http://orgmode.org |
| 9 | ;; Version: 7.7 | ||
| 10 | 9 | ||
| 11 | ;; This file is part of GNU Emacs. | 10 | ;; This file is part of GNU Emacs. |
| 12 | 11 | ||
| @@ -80,7 +79,8 @@ | |||
| 80 | "Execute a block of R code. | 79 | "Execute a block of R code. |
| 81 | This function is called by `org-babel-execute-src-block'." | 80 | This function is called by `org-babel-execute-src-block'." |
| 82 | (save-excursion | 81 | (save-excursion |
| 83 | (let* ((result-type (cdr (assoc :result-type params))) | 82 | (let* ((result-params (cdr (assoc :result-params params))) |
| 83 | (result-type (cdr (assoc :result-type params))) | ||
| 84 | (session (org-babel-R-initiate-session | 84 | (session (org-babel-R-initiate-session |
| 85 | (cdr (assoc :session params)) params)) | 85 | (cdr (assoc :session params)) params)) |
| 86 | (colnames-p (cdr (assoc :colnames params))) | 86 | (colnames-p (cdr (assoc :colnames params))) |
| @@ -89,7 +89,7 @@ This function is called by `org-babel-execute-src-block'." | |||
| 89 | (full-body (org-babel-expand-body:R body params graphics-file)) | 89 | (full-body (org-babel-expand-body:R body params graphics-file)) |
| 90 | (result | 90 | (result |
| 91 | (org-babel-R-evaluate | 91 | (org-babel-R-evaluate |
| 92 | session full-body result-type | 92 | session full-body result-type result-params |
| 93 | (or (equal "yes" colnames-p) | 93 | (or (equal "yes" colnames-p) |
| 94 | (org-babel-pick-name | 94 | (org-babel-pick-name |
| 95 | (cdr (assoc :colname-names params)) colnames-p)) | 95 | (cdr (assoc :colname-names params)) colnames-p)) |
| @@ -197,6 +197,7 @@ current code buffer." | |||
| 197 | '((:bmp . "bmp") | 197 | '((:bmp . "bmp") |
| 198 | (:jpg . "jpeg") | 198 | (:jpg . "jpeg") |
| 199 | (:jpeg . "jpeg") | 199 | (:jpeg . "jpeg") |
| 200 | (:tex . "tikz") | ||
| 200 | (:tiff . "tiff") | 201 | (:tiff . "tiff") |
| 201 | (:png . "png") | 202 | (:png . "png") |
| 202 | (:svg . "svg") | 203 | (:svg . "svg") |
| @@ -214,7 +215,7 @@ current code buffer." | |||
| 214 | (setq device (or (and device (cdr (assq (intern (concat ":" device)) | 215 | (setq device (or (and device (cdr (assq (intern (concat ":" device)) |
| 215 | devices))) "png")) | 216 | devices))) "png")) |
| 216 | (setq filearg | 217 | (setq filearg |
| 217 | (if (member device '("pdf" "postscript" "svg")) "file" "filename")) | 218 | (if (member device '("pdf" "postscript" "svg" "tikz")) "file" "filename")) |
| 218 | (setq args (mapconcat | 219 | (setq args (mapconcat |
| 219 | (lambda (pair) | 220 | (lambda (pair) |
| 220 | (if (member (car pair) allowed-args) | 221 | (if (member (car pair) allowed-args) |
| @@ -232,16 +233,16 @@ current code buffer." | |||
| 232 | (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\")") | 233 | (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\")") |
| 233 | 234 | ||
| 234 | (defun org-babel-R-evaluate | 235 | (defun org-babel-R-evaluate |
| 235 | (session body result-type column-names-p row-names-p) | 236 | (session body result-type result-params column-names-p row-names-p) |
| 236 | "Evaluate R code in BODY." | 237 | "Evaluate R code in BODY." |
| 237 | (if session | 238 | (if session |
| 238 | (org-babel-R-evaluate-session | 239 | (org-babel-R-evaluate-session |
| 239 | session body result-type column-names-p row-names-p) | 240 | session body result-type result-params column-names-p row-names-p) |
| 240 | (org-babel-R-evaluate-external-process | 241 | (org-babel-R-evaluate-external-process |
| 241 | body result-type column-names-p row-names-p))) | 242 | body result-type result-params column-names-p row-names-p))) |
| 242 | 243 | ||
| 243 | (defun org-babel-R-evaluate-external-process | 244 | (defun org-babel-R-evaluate-external-process |
| 244 | (body result-type column-names-p row-names-p) | 245 | (body result-type result-params column-names-p row-names-p) |
| 245 | "Evaluate BODY in external R process. | 246 | "Evaluate BODY in external R process. |
| 246 | If RESULT-TYPE equals 'output then return standard output as a | 247 | If RESULT-TYPE equals 'output then return standard output as a |
| 247 | string. If RESULT-TYPE equals 'value then return the value of the | 248 | string. If RESULT-TYPE equals 'value then return the value of the |
| @@ -258,11 +259,17 @@ last statement in BODY, as elisp." | |||
| 258 | (format "{function ()\n{\n%s\n}}()" body) | 259 | (format "{function ()\n{\n%s\n}}()" body) |
| 259 | (org-babel-process-file-name tmp-file 'noquote))) | 260 | (org-babel-process-file-name tmp-file 'noquote))) |
| 260 | (org-babel-R-process-value-result | 261 | (org-babel-R-process-value-result |
| 261 | (org-babel-import-elisp-from-file tmp-file '(16)) column-names-p))) | 262 | (if (or (member "scalar" result-params) |
| 263 | (member "verbatim" result-params)) | ||
| 264 | (with-temp-buffer | ||
| 265 | (insert-file-contents tmp-file) | ||
| 266 | (buffer-string)) | ||
| 267 | (org-babel-import-elisp-from-file tmp-file '(16))) | ||
| 268 | column-names-p))) | ||
| 262 | (output (org-babel-eval org-babel-R-command body)))) | 269 | (output (org-babel-eval org-babel-R-command body)))) |
| 263 | 270 | ||
| 264 | (defun org-babel-R-evaluate-session | 271 | (defun org-babel-R-evaluate-session |
| 265 | (session body result-type column-names-p row-names-p) | 272 | (session body result-type result-params column-names-p row-names-p) |
| 266 | "Evaluate BODY in SESSION. | 273 | "Evaluate BODY in SESSION. |
| 267 | If RESULT-TYPE equals 'output then return standard output as a | 274 | If RESULT-TYPE equals 'output then return standard output as a |
| 268 | string. If RESULT-TYPE equals 'value then return the value of the | 275 | string. If RESULT-TYPE equals 'value then return the value of the |
| @@ -284,7 +291,13 @@ last statement in BODY, as elisp." | |||
| 284 | "FALSE") | 291 | "FALSE") |
| 285 | ".Last.value" (org-babel-process-file-name tmp-file 'noquote))) | 292 | ".Last.value" (org-babel-process-file-name tmp-file 'noquote))) |
| 286 | (org-babel-R-process-value-result | 293 | (org-babel-R-process-value-result |
| 287 | (org-babel-import-elisp-from-file tmp-file '(16)) column-names-p))) | 294 | (if (or (member "scalar" result-params) |
| 295 | (member "verbatim" result-params)) | ||
| 296 | (with-temp-buffer | ||
| 297 | (insert-file-contents tmp-file) | ||
| 298 | (buffer-string)) | ||
| 299 | (org-babel-import-elisp-from-file tmp-file '(16))) | ||
| 300 | column-names-p))) | ||
| 288 | (output | 301 | (output |
| 289 | (mapconcat | 302 | (mapconcat |
| 290 | #'org-babel-chomp | 303 | #'org-babel-chomp |
| @@ -295,7 +308,7 @@ last statement in BODY, as elisp." | |||
| 295 | (mapcar | 308 | (mapcar |
| 296 | (lambda (line) ;; cleanup extra prompts left in output | 309 | (lambda (line) ;; cleanup extra prompts left in output |
| 297 | (if (string-match | 310 | (if (string-match |
| 298 | "^\\([ ]*[>+][ ]?\\)+\\([[0-9]+\\|[ ]\\)" line) | 311 | "^\\([ ]*[>+\\.][ ]?\\)+\\([[0-9]+\\|[ ]\\)" line) |
| 299 | (substring line (match-end 1)) | 312 | (substring line (match-end 1)) |
| 300 | line)) | 313 | line)) |
| 301 | (org-babel-comint-with-output (session org-babel-R-eoe-output) | 314 | (org-babel-comint-with-output (session org-babel-R-eoe-output) |