diff options
| author | Bastien Guerry | 2013-11-12 14:06:26 +0100 |
|---|---|---|
| committer | Bastien Guerry | 2013-11-12 14:06:26 +0100 |
| commit | 271672fad74cdbc9065d23d6e6cee1b8540f571b (patch) | |
| tree | d322b956ec0e74ee33b22354ef00839b23b1618d /lisp/org/ob-R.el | |
| parent | f201cf3a8143b0b34b07769fc7d73dd14761b87b (diff) | |
| download | emacs-271672fad74cdbc9065d23d6e6cee1b8540f571b.tar.gz emacs-271672fad74cdbc9065d23d6e6cee1b8540f571b.zip | |
Merge Org version 8.2.3a.
Diffstat (limited to 'lisp/org/ob-R.el')
| -rw-r--r-- | lisp/org/ob-R.el | 88 |
1 files changed, 50 insertions, 38 deletions
diff --git a/lisp/org/ob-R.el b/lisp/org/ob-R.el index 562f37d7b95..74d7513df3e 100644 --- a/lisp/org/ob-R.el +++ b/lisp/org/ob-R.el | |||
| @@ -28,9 +28,6 @@ | |||
| 28 | 28 | ||
| 29 | ;;; Code: | 29 | ;;; Code: |
| 30 | (require 'ob) | 30 | (require 'ob) |
| 31 | (require 'ob-ref) | ||
| 32 | (require 'ob-comint) | ||
| 33 | (require 'ob-eval) | ||
| 34 | (eval-when-compile (require 'cl)) | 31 | (eval-when-compile (require 'cl)) |
| 35 | 32 | ||
| 36 | (declare-function orgtbl-to-tsv "org-table" (table params)) | 33 | (declare-function orgtbl-to-tsv "org-table" (table params)) |
| @@ -96,8 +93,13 @@ | |||
| 96 | inside | 93 | inside |
| 97 | (list "dev.off()")) | 94 | (list "dev.off()")) |
| 98 | inside)) | 95 | inside)) |
| 99 | (append (org-babel-variable-assignments:R params) | 96 | (append |
| 100 | (list body))) "\n"))) | 97 | (when (cdr (assoc :prologue params)) |
| 98 | (list (cdr (assoc :prologue params)))) | ||
| 99 | (org-babel-variable-assignments:R params) | ||
| 100 | (list body) | ||
| 101 | (when (cdr (assoc :epilogue params)) | ||
| 102 | (list (cdr (assoc :epilogue params)))))) "\n"))) | ||
| 101 | 103 | ||
| 102 | (defun org-babel-execute:R (body params) | 104 | (defun org-babel-execute:R (body params) |
| 103 | "Execute a block of R code. | 105 | "Execute a block of R code. |
| @@ -212,6 +214,9 @@ This function is called by `org-babel-execute-src-block'." | |||
| 212 | (if (org-babel-comint-buffer-livep session) | 214 | (if (org-babel-comint-buffer-livep session) |
| 213 | session | 215 | session |
| 214 | (save-window-excursion | 216 | (save-window-excursion |
| 217 | (when (get-buffer session) | ||
| 218 | ;; Session buffer exists, but with dead process | ||
| 219 | (set-buffer session)) | ||
| 215 | (require 'ess) (R) | 220 | (require 'ess) (R) |
| 216 | (rename-buffer | 221 | (rename-buffer |
| 217 | (if (bufferp session) | 222 | (if (bufferp session) |
| @@ -234,31 +239,40 @@ current code buffer." | |||
| 234 | (and (member "graphics" (cdr (assq :result-params params))) | 239 | (and (member "graphics" (cdr (assq :result-params params))) |
| 235 | (cdr (assq :file params)))) | 240 | (cdr (assq :file params)))) |
| 236 | 241 | ||
| 242 | (defvar org-babel-R-graphics-devices | ||
| 243 | '((:bmp "bmp" "filename") | ||
| 244 | (:jpg "jpeg" "filename") | ||
| 245 | (:jpeg "jpeg" "filename") | ||
| 246 | (:tikz "tikz" "file") | ||
| 247 | (:tiff "tiff" "filename") | ||
| 248 | (:png "png" "filename") | ||
| 249 | (:svg "svg" "file") | ||
| 250 | (:pdf "pdf" "file") | ||
| 251 | (:ps "postscript" "file") | ||
| 252 | (:postscript "postscript" "file")) | ||
| 253 | "An alist mapping graphics file types to R functions. | ||
| 254 | |||
| 255 | Each member of this list is a list with three members: | ||
| 256 | 1. the file extension of the graphics file, as an elisp :keyword | ||
| 257 | 2. the R graphics device function to call to generate such a file | ||
| 258 | 3. the name of the argument to this function which specifies the | ||
| 259 | file to write to (typically \"file\" or \"filename\")") | ||
| 260 | |||
| 237 | (defun org-babel-R-construct-graphics-device-call (out-file params) | 261 | (defun org-babel-R-construct-graphics-device-call (out-file params) |
| 238 | "Construct the call to the graphics device." | 262 | "Construct the call to the graphics device." |
| 239 | (let ((devices | 263 | (let* ((allowed-args '(:width :height :bg :units :pointsize |
| 240 | '((:bmp . "bmp") | 264 | :antialias :quality :compression :res |
| 241 | (:jpg . "jpeg") | 265 | :type :family :title :fonts :version |
| 242 | (:jpeg . "jpeg") | 266 | :paper :encoding :pagecentre :colormodel |
| 243 | (:tex . "tikz") | 267 | :useDingbats :horizontal)) |
| 244 | (:tiff . "tiff") | 268 | (device (and (string-match ".+\\.\\([^.]+\\)" out-file) |
| 245 | (:png . "png") | 269 | (match-string 1 out-file))) |
| 246 | (:svg . "svg") | 270 | (device-info (or (assq (intern (concat ":" device)) |
| 247 | (:pdf . "pdf") | 271 | org-babel-R-graphics-devices) |
| 248 | (:ps . "postscript") | 272 | (assq :png org-babel-R-graphics-devices))) |
| 249 | (:postscript . "postscript"))) | 273 | (extra-args (cdr (assq :R-dev-args params))) filearg args) |
| 250 | (allowed-args '(:width :height :bg :units :pointsize | 274 | (setq device (nth 1 device-info)) |
| 251 | :antialias :quality :compression :res | 275 | (setq filearg (nth 2 device-info)) |
| 252 | :type :family :title :fonts :version | ||
| 253 | :paper :encoding :pagecentre :colormodel | ||
| 254 | :useDingbats :horizontal)) | ||
| 255 | (device (and (string-match ".+\\.\\([^.]+\\)" out-file) | ||
| 256 | (match-string 1 out-file))) | ||
| 257 | (extra-args (cdr (assq :R-dev-args params))) filearg args) | ||
| 258 | (setq device (or (and device (cdr (assq (intern (concat ":" device)) | ||
| 259 | devices))) "png")) | ||
| 260 | (setq filearg | ||
| 261 | (if (member device '("pdf" "postscript" "svg" "tikz")) "file" "filename")) | ||
| 262 | (setq args (mapconcat | 276 | (setq args (mapconcat |
| 263 | (lambda (pair) | 277 | (lambda (pair) |
| 264 | (if (member (car pair) allowed-args) | 278 | (if (member (car pair) allowed-args) |
| @@ -302,11 +316,10 @@ last statement in BODY, as elisp." | |||
| 302 | (format "{function ()\n{\n%s\n}}()" body) | 316 | (format "{function ()\n{\n%s\n}}()" body) |
| 303 | (org-babel-process-file-name tmp-file 'noquote))) | 317 | (org-babel-process-file-name tmp-file 'noquote))) |
| 304 | (org-babel-R-process-value-result | 318 | (org-babel-R-process-value-result |
| 305 | (if (or (member "scalar" result-params) | 319 | (org-babel-result-cond result-params |
| 306 | (member "verbatim" result-params)) | 320 | (with-temp-buffer |
| 307 | (with-temp-buffer | 321 | (insert-file-contents tmp-file) |
| 308 | (insert-file-contents tmp-file) | 322 | (buffer-string)) |
| 309 | (buffer-string)) | ||
| 310 | (org-babel-import-elisp-from-file tmp-file '(16))) | 323 | (org-babel-import-elisp-from-file tmp-file '(16))) |
| 311 | column-names-p))) | 324 | column-names-p))) |
| 312 | (output (org-babel-eval org-babel-R-command body)))) | 325 | (output (org-babel-eval org-babel-R-command body)))) |
| @@ -335,11 +348,10 @@ last statement in BODY, as elisp." | |||
| 335 | "FALSE") | 348 | "FALSE") |
| 336 | ".Last.value" (org-babel-process-file-name tmp-file 'noquote))) | 349 | ".Last.value" (org-babel-process-file-name tmp-file 'noquote))) |
| 337 | (org-babel-R-process-value-result | 350 | (org-babel-R-process-value-result |
| 338 | (if (or (member "scalar" result-params) | 351 | (org-babel-result-cond result-params |
| 339 | (member "verbatim" result-params)) | 352 | (with-temp-buffer |
| 340 | (with-temp-buffer | 353 | (insert-file-contents tmp-file) |
| 341 | (insert-file-contents tmp-file) | 354 | (buffer-string)) |
| 342 | (buffer-string)) | ||
| 343 | (org-babel-import-elisp-from-file tmp-file '(16))) | 355 | (org-babel-import-elisp-from-file tmp-file '(16))) |
| 344 | column-names-p))) | 356 | column-names-p))) |
| 345 | (output | 357 | (output |