diff options
| author | Bastien Guerry | 2011-07-28 17:13:49 +0200 |
|---|---|---|
| committer | Bastien Guerry | 2011-07-28 17:13:49 +0200 |
| commit | 3ab2c837b302b01fff610f7b83050ab7e703477c (patch) | |
| tree | efa67ed523bbda4d41488ae6b9ad2782941ddcf2 /lisp/org/ob-R.el | |
| parent | 44a8054f971837447e80d618b6e0c2a77778a2ee (diff) | |
| download | emacs-3ab2c837b302b01fff610f7b83050ab7e703477c.tar.gz emacs-3ab2c837b302b01fff610f7b83050ab7e703477c.zip | |
Merge changes from Org 7.4 to current Org 7.7.
Diffstat (limited to 'lisp/org/ob-R.el')
| -rw-r--r-- | lisp/org/ob-R.el | 37 |
1 files changed, 26 insertions, 11 deletions
diff --git a/lisp/org/ob-R.el b/lisp/org/ob-R.el index 5f94240f22f..35cdcb90926 100644 --- a/lisp/org/ob-R.el +++ b/lisp/org/ob-R.el | |||
| @@ -1,11 +1,11 @@ | |||
| 1 | ;;; ob-R.el --- org-babel functions for R code evaluation | 1 | ;;; ob-R.el --- org-babel functions for R code evaluation |
| 2 | 2 | ||
| 3 | ;; Copyright (C) 2009-2011 Free Software Foundation, Inc. | 3 | ;; Copyright (C) 2009, 2010 Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | ;; Author: Eric Schulte, Dan Davison | 5 | ;; Author: Eric Schulte, Dan Davison |
| 6 | ;; Keywords: literate programming, reproducible research, R, statistics | 6 | ;; Keywords: literate programming, reproducible research, R, statistics |
| 7 | ;; Homepage: http://orgmode.org | 7 | ;; Homepage: http://orgmode.org |
| 8 | ;; Version: 7.4 | 8 | ;; Version: 7.7 |
| 9 | 9 | ||
| 10 | ;; This file is part of GNU Emacs. | 10 | ;; This file is part of GNU Emacs. |
| 11 | 11 | ||
| @@ -51,15 +51,24 @@ | |||
| 51 | (defvar org-babel-R-command "R --slave --no-save" | 51 | (defvar org-babel-R-command "R --slave --no-save" |
| 52 | "Name of command to use for executing R code.") | 52 | "Name of command to use for executing R code.") |
| 53 | 53 | ||
| 54 | (defun org-babel-expand-body:R (body params) | 54 | (defvar ess-local-process-name) |
| 55 | (defun org-babel-edit-prep:R (info) | ||
| 56 | (let ((session (cdr (assoc :session (nth 2 info))))) | ||
| 57 | (when (and session (string-match "^\\*\\(.+?\\)\\*$" session)) | ||
| 58 | (save-match-data (org-babel-R-initiate-session session nil)) | ||
| 59 | (setq ess-local-process-name (match-string 1 session))))) | ||
| 60 | |||
| 61 | (defun org-babel-expand-body:R (body params &optional graphics-file) | ||
| 55 | "Expand BODY according to PARAMS, return the expanded body." | 62 | "Expand BODY according to PARAMS, return the expanded body." |
| 56 | (let ((out-file (cdr (assoc :file params)))) | 63 | (let ((graphics-file |
| 64 | (or graphics-file (org-babel-R-graphical-output-file params)))) | ||
| 57 | (mapconcat | 65 | (mapconcat |
| 58 | #'identity | 66 | #'identity |
| 59 | ((lambda (inside) | 67 | ((lambda (inside) |
| 60 | (if out-file | 68 | (if graphics-file |
| 61 | (append | 69 | (append |
| 62 | (list (org-babel-R-construct-graphics-device-call out-file params)) | 70 | (list (org-babel-R-construct-graphics-device-call |
| 71 | graphics-file params)) | ||
| 63 | inside | 72 | inside |
| 64 | (list "dev.off()")) | 73 | (list "dev.off()")) |
| 65 | inside)) | 74 | inside)) |
| @@ -75,8 +84,8 @@ This function is called by `org-babel-execute-src-block'." | |||
| 75 | (cdr (assoc :session params)) params)) | 84 | (cdr (assoc :session params)) params)) |
| 76 | (colnames-p (cdr (assoc :colnames params))) | 85 | (colnames-p (cdr (assoc :colnames params))) |
| 77 | (rownames-p (cdr (assoc :rownames params))) | 86 | (rownames-p (cdr (assoc :rownames params))) |
| 78 | (out-file (cdr (assoc :file params))) | 87 | (graphics-file (org-babel-R-graphical-output-file params)) |
| 79 | (full-body (org-babel-expand-body:R body params)) | 88 | (full-body (org-babel-expand-body:R body params graphics-file)) |
| 80 | (result | 89 | (result |
| 81 | (org-babel-R-evaluate | 90 | (org-babel-R-evaluate |
| 82 | session full-body result-type | 91 | session full-body result-type |
| @@ -86,8 +95,7 @@ This function is called by `org-babel-execute-src-block'." | |||
| 86 | (or (equal "yes" rownames-p) | 95 | (or (equal "yes" rownames-p) |
| 87 | (org-babel-pick-name | 96 | (org-babel-pick-name |
| 88 | (cdr (assoc :rowname-names params)) rownames-p))))) | 97 | (cdr (assoc :rowname-names params)) rownames-p))))) |
| 89 | (message "result is %S" result) | 98 | (if graphics-file nil result)))) |
| 90 | (or out-file result)))) | ||
| 91 | 99 | ||
| 92 | (defun org-babel-prep-session:R (session params) | 100 | (defun org-babel-prep-session:R (session params) |
| 93 | "Prepare SESSION according to the header arguments specified in PARAMS." | 101 | "Prepare SESSION according to the header arguments specified in PARAMS." |
| @@ -177,6 +185,11 @@ current code buffer." | |||
| 177 | (process-name (get-buffer-process session))) | 185 | (process-name (get-buffer-process session))) |
| 178 | (ess-make-buffer-current)) | 186 | (ess-make-buffer-current)) |
| 179 | 187 | ||
| 188 | (defun org-babel-R-graphical-output-file (params) | ||
| 189 | "Name of file to which R should send graphical output." | ||
| 190 | (and (member "graphics" (cdr (assq :result-params params))) | ||
| 191 | (cdr (assq :file params)))) | ||
| 192 | |||
| 180 | (defun org-babel-R-construct-graphics-device-call (out-file params) | 193 | (defun org-babel-R-construct-graphics-device-call (out-file params) |
| 181 | "Construct the call to the graphics device." | 194 | "Construct the call to the graphics device." |
| 182 | (let ((devices | 195 | (let ((devices |
| @@ -214,7 +227,8 @@ current code buffer." | |||
| 214 | 227 | ||
| 215 | (defvar org-babel-R-eoe-indicator "'org_babel_R_eoe'") | 228 | (defvar org-babel-R-eoe-indicator "'org_babel_R_eoe'") |
| 216 | (defvar org-babel-R-eoe-output "[1] \"org_babel_R_eoe\"") | 229 | (defvar org-babel-R-eoe-output "[1] \"org_babel_R_eoe\"") |
| 217 | (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\")") | 230 | |
| 231 | (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\")") | ||
| 218 | 232 | ||
| 219 | (defun org-babel-R-evaluate | 233 | (defun org-babel-R-evaluate |
| 220 | (session body result-type column-names-p row-names-p) | 234 | (session body result-type column-names-p row-names-p) |
| @@ -298,5 +312,6 @@ Insert hline if column names in output have been requested." | |||
| 298 | 312 | ||
| 299 | (provide 'ob-R) | 313 | (provide 'ob-R) |
| 300 | 314 | ||
| 315 | ;; arch-tag: cd4c7298-503b-450f-a3c2-f3e74b630237 | ||
| 301 | 316 | ||
| 302 | ;;; ob-R.el ends here | 317 | ;;; ob-R.el ends here |