Mercurial > emacs
annotate lisp/org/ob-R.el @ 112445:93fcbcb698b0
Improve configuration of makeinfo.
* Makefile.in (MAKEINFO): Now controlled by `configure'.
(MAKEINFO_OPTS): New variable. Use it where appropriate.
(ENVADD): Updated.
author | Werner Lemberg <wl@gnu.org> |
---|---|
date | Sun, 23 Jan 2011 11:38:14 +0100 |
parents | ef719132ddfa |
children |
rev | line source |
---|---|
109462
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
1 ;;; ob-R.el --- org-babel functions for R code evaluation |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
2 |
112275
6378d1b57038
Add 2011 to remaining FSF/AIST copyright years.
Glenn Morris <rgm@gnu.org>
parents:
111880
diff
changeset
|
3 ;; Copyright (C) 2009, 2010, 2011 Free Software Foundation, Inc. |
109462
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
4 |
111880
a7740098b594
Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents:
111521
diff
changeset
|
5 ;; Author: Eric Schulte, Dan Davison |
109462
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
6 ;; Keywords: literate programming, reproducible research, R, statistics |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
7 ;; Homepage: http://orgmode.org |
111880
a7740098b594
Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents:
111521
diff
changeset
|
8 ;; Version: 7.4 |
109462
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
9 |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
10 ;; This file is part of GNU Emacs. |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
11 |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
12 ;; GNU Emacs is free software: you can redistribute it and/or modify |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
13 ;; it under the terms of the GNU General Public License as published by |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
14 ;; the Free Software Foundation, either version 3 of the License, or |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
15 ;; (at your option) any later version. |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
16 |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
17 ;; GNU Emacs is distributed in the hope that it will be useful, |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
20 ;; GNU General Public License for more details. |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
21 |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
22 ;; You should have received a copy of the GNU General Public License |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
24 |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
25 ;;; Commentary: |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
26 |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
27 ;; Org-Babel support for evaluating R code |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
28 |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
29 ;;; Code: |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
30 (require 'ob) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
31 (require 'ob-ref) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
32 (require 'ob-comint) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
33 (require 'ob-eval) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
34 (eval-when-compile (require 'cl)) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
35 |
109812
063e94b66261
Fix some Org errors revealed by `make check-declare'.
Glenn Morris <rgm@gnu.org>
parents:
109462
diff
changeset
|
36 (declare-function orgtbl-to-tsv "org-table" (table params)) |
109462
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
37 (declare-function R "ext:essd-r" (&optional start-args)) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
38 (declare-function inferior-ess-send-input "ext:ess-inf" ()) |
111506
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
39 (declare-function ess-make-buffer-current "ext:ess-inf" ()) |
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
40 (declare-function ess-eval-buffer "ext:ess-inf" (vis)) |
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
41 (declare-function org-number-sequence "org-compat" (from &optional to inc)) |
109462
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
42 |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
43 (defconst org-babel-header-arg-names:R |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
44 '(width height bg units pointsize antialias quality compression |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
45 res type family title fonts version paper encoding |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
46 pagecentre colormodel useDingbats horizontal) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
47 "R-specific header arguments.") |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
48 |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
49 (defvar org-babel-default-header-args:R '()) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
50 |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
51 (defvar org-babel-R-command "R --slave --no-save" |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
52 "Name of command to use for executing R code.") |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
53 |
111506
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
54 (defun org-babel-expand-body:R (body params) |
109462
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
55 "Expand BODY according to PARAMS, return the expanded body." |
111506
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
56 (let ((out-file (cdr (assoc :file params)))) |
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
57 (mapconcat |
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
58 #'identity |
109462
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
59 ((lambda (inside) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
60 (if out-file |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
61 (append |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
62 (list (org-babel-R-construct-graphics-device-call out-file params)) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
63 inside |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
64 (list "dev.off()")) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
65 inside)) |
111506
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
66 (append (org-babel-variable-assignments:R params) |
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
67 (list body))) "\n"))) |
109462
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
68 |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
69 (defun org-babel-execute:R (body params) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
70 "Execute a block of R code. |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
71 This function is called by `org-babel-execute-src-block'." |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
72 (save-excursion |
111506
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
73 (let* ((result-type (cdr (assoc :result-type params))) |
109462
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
74 (session (org-babel-R-initiate-session |
111506
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
75 (cdr (assoc :session params)) params)) |
109462
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
76 (colnames-p (cdr (assoc :colnames params))) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
77 (rownames-p (cdr (assoc :rownames params))) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
78 (out-file (cdr (assoc :file params))) |
111506
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
79 (full-body (org-babel-expand-body:R body params)) |
109462
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
80 (result |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
81 (org-babel-R-evaluate |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
82 session full-body result-type |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
83 (or (equal "yes" colnames-p) |
111506
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
84 (org-babel-pick-name |
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
85 (cdr (assoc :colname-names params)) colnames-p)) |
109462
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
86 (or (equal "yes" rownames-p) |
111506
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
87 (org-babel-pick-name |
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
88 (cdr (assoc :rowname-names params)) rownames-p))))) |
109462
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
89 (message "result is %S" result) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
90 (or out-file result)))) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
91 |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
92 (defun org-babel-prep-session:R (session params) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
93 "Prepare SESSION according to the header arguments specified in PARAMS." |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
94 (let* ((session (org-babel-R-initiate-session session params)) |
111506
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
95 (var-lines (org-babel-variable-assignments:R params))) |
109462
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
96 (org-babel-comint-in-buffer session |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
97 (mapc (lambda (var) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
98 (end-of-line 1) (insert var) (comint-send-input nil t) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
99 (org-babel-comint-wait-for-output session)) var-lines)) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
100 session)) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
101 |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
102 (defun org-babel-load-session:R (session body params) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
103 "Load BODY into SESSION." |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
104 (save-window-excursion |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
105 (let ((buffer (org-babel-prep-session:R session params))) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
106 (with-current-buffer buffer |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
107 (goto-char (process-mark (get-buffer-process (current-buffer)))) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
108 (insert (org-babel-chomp body))) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
109 buffer))) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
110 |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
111 ;; helper functions |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
112 |
111506
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
113 (defun org-babel-variable-assignments:R (params) |
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
114 "Return list of R statements assigning the block's variables" |
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
115 (let ((vars (mapcar #'cdr (org-babel-get-header params :var)))) |
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
116 (mapcar |
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
117 (lambda (pair) |
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
118 (org-babel-R-assign-elisp |
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
119 (car pair) (cdr pair) |
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
120 (equal "yes" (cdr (assoc :colnames params))) |
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
121 (equal "yes" (cdr (assoc :rownames params))))) |
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
122 (mapcar |
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
123 (lambda (i) |
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
124 (cons (car (nth i vars)) |
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
125 (org-babel-reassemble-table |
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
126 (cdr (nth i vars)) |
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
127 (cdr (nth i (cdr (assoc :colname-names params)))) |
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
128 (cdr (nth i (cdr (assoc :rowname-names params))))))) |
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
129 (org-number-sequence 0 (1- (length vars))))))) |
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
130 |
109462
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
131 (defun org-babel-R-quote-tsv-field (s) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
132 "Quote field S for export to R." |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
133 (if (stringp s) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
134 (concat "\"" (mapconcat 'identity (split-string s "\"") "\"\"") "\"") |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
135 (format "%S" s))) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
136 |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
137 (defun org-babel-R-assign-elisp (name value colnames-p rownames-p) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
138 "Construct R code assigning the elisp VALUE to a variable named NAME." |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
139 (if (listp value) |
111506
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
140 (let ((transition-file (org-babel-temp-file "R-import-"))) |
109462
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
141 ;; ensure VALUE has an orgtbl structure (depth of at least 2) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
142 (unless (listp (car value)) (setq value (list value))) |
111506
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
143 (with-temp-file transition-file |
109462
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
144 (insert (orgtbl-to-tsv value '(:fmt org-babel-R-quote-tsv-field))) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
145 (insert "\n")) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
146 (format "%s <- read.table(\"%s\", header=%s, row.names=%s, sep=\"\\t\", as.is=TRUE)" |
111506
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
147 name (org-babel-process-file-name transition-file 'noquote) |
109462
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
148 (if (or (eq (nth 1 value) 'hline) colnames-p) "TRUE" "FALSE") |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
149 (if rownames-p "1" "NULL"))) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
150 (format "%s <- %s" name (org-babel-R-quote-tsv-field value)))) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
151 |
111506
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
152 (defvar ess-ask-for-ess-directory nil) |
109462
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
153 (defun org-babel-R-initiate-session (session params) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
154 "If there is not a current R process then create one." |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
155 (unless (string= session "none") |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
156 (let ((session (or session "*R*")) |
111506
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
157 (ess-ask-for-ess-directory |
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
158 (and ess-ask-for-ess-directory (not (cdr (assoc :dir params)))))) |
109462
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
159 (if (org-babel-comint-buffer-livep session) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
160 session |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
161 (save-window-excursion |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
162 (require 'ess) (R) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
163 (rename-buffer |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
164 (if (bufferp session) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
165 (buffer-name session) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
166 (if (stringp session) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
167 session |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
168 (buffer-name)))) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
169 (current-buffer)))))) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
170 |
111506
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
171 (defvar ess-local-process-name nil) |
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
172 (defun org-babel-R-associate-session (session) |
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
173 "Associate R code buffer with an R session. |
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
174 Make SESSION be the inferior ESS process associated with the |
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
175 current code buffer." |
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
176 (setq ess-local-process-name |
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
177 (process-name (get-buffer-process session))) |
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
178 (ess-make-buffer-current)) |
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
179 |
109462
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
180 (defun org-babel-R-construct-graphics-device-call (out-file params) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
181 "Construct the call to the graphics device." |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
182 (let ((devices |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
183 '((:bmp . "bmp") |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
184 (:jpg . "jpeg") |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
185 (:jpeg . "jpeg") |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
186 (:tiff . "tiff") |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
187 (:png . "png") |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
188 (:svg . "svg") |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
189 (:pdf . "pdf") |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
190 (:ps . "postscript") |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
191 (:postscript . "postscript"))) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
192 (allowed-args '(:width :height :bg :units :pointsize |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
193 :antialias :quality :compression :res |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
194 :type :family :title :fonts :version |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
195 :paper :encoding :pagecentre :colormodel |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
196 :useDingbats :horizontal)) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
197 (device (and (string-match ".+\\.\\([^.]+\\)" out-file) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
198 (match-string 1 out-file))) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
199 (extra-args (cdr (assq :R-dev-args params))) filearg args) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
200 (setq device (or (and device (cdr (assq (intern (concat ":" device)) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
201 devices))) "png")) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
202 (setq filearg |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
203 (if (member device '("pdf" "postscript" "svg")) "file" "filename")) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
204 (setq args (mapconcat |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
205 (lambda (pair) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
206 (if (member (car pair) allowed-args) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
207 (format ",%s=%s" |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
208 (substring (symbol-name (car pair)) 1) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
209 (cdr pair)) "")) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
210 params "")) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
211 (format "%s(%s=\"%s\"%s%s%s)" |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
212 device filearg out-file args |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
213 (if extra-args "," "") (or extra-args "")))) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
214 |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
215 (defvar org-babel-R-eoe-indicator "'org_babel_R_eoe'") |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
216 (defvar org-babel-R-eoe-output "[1] \"org_babel_R_eoe\"") |
111506
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
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\")") |
109462
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
218 |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
219 (defun org-babel-R-evaluate |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
220 (session body result-type column-names-p row-names-p) |
111506
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
221 "Evaluate R code in BODY." |
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
222 (if session |
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
223 (org-babel-R-evaluate-session |
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
224 session body result-type column-names-p row-names-p) |
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
225 (org-babel-R-evaluate-external-process |
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
226 body result-type column-names-p row-names-p))) |
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
227 |
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
228 (defun org-babel-R-evaluate-external-process |
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
229 (body result-type column-names-p row-names-p) |
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
230 "Evaluate BODY in external R process. |
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
231 If RESULT-TYPE equals 'output then return standard output as a |
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
232 string. If RESULT-TYPE equals 'value then return the value of the |
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
233 last statement in BODY, as elisp." |
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
234 (case result-type |
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
235 (value |
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
236 (let ((tmp-file (org-babel-temp-file "R-"))) |
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
237 (org-babel-eval org-babel-R-command |
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
238 (format org-babel-R-write-object-command |
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
239 (if row-names-p "TRUE" "FALSE") |
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
240 (if column-names-p |
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
241 (if row-names-p "NA" "TRUE") |
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
242 "FALSE") |
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
243 (format "{function ()\n{\n%s\n}}()" body) |
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
244 (org-babel-process-file-name tmp-file 'noquote))) |
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
245 (org-babel-R-process-value-result |
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
246 (org-babel-import-elisp-from-file tmp-file '(16)) column-names-p))) |
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
247 (output (org-babel-eval org-babel-R-command body)))) |
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
248 |
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
249 (defun org-babel-R-evaluate-session |
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
250 (session body result-type column-names-p row-names-p) |
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
251 "Evaluate BODY in SESSION. |
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
252 If RESULT-TYPE equals 'output then return standard output as a |
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
253 string. If RESULT-TYPE equals 'value then return the value of the |
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
254 last statement in BODY, as elisp." |
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
255 (case result-type |
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
256 (value |
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
257 (with-temp-buffer |
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
258 (insert (org-babel-chomp body)) |
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
259 (let ((ess-local-process-name |
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
260 (process-name (get-buffer-process session)))) |
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
261 (ess-eval-buffer nil))) |
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
262 (let ((tmp-file (org-babel-temp-file "R-"))) |
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
263 (org-babel-comint-eval-invisibly-and-wait-for-file |
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
264 session tmp-file |
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
265 (format org-babel-R-write-object-command |
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
266 (if row-names-p "TRUE" "FALSE") |
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
267 (if column-names-p |
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
268 (if row-names-p "NA" "TRUE") |
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
269 "FALSE") |
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
270 ".Last.value" (org-babel-process-file-name tmp-file 'noquote))) |
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
271 (org-babel-R-process-value-result |
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
272 (org-babel-import-elisp-from-file tmp-file '(16)) column-names-p))) |
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
273 (output |
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
274 (mapconcat |
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
275 #'org-babel-chomp |
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
276 (butlast |
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
277 (delq nil |
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109812
diff
changeset
|
278 (mapcar |
111880
a7740098b594
Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents:
111521
diff
changeset
|
279 (lambda (line) (when (> (length line) 0) line)) |
a7740098b594
Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents:
111521
diff
changeset
|
280 (mapcar |
a7740098b594
Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents:
111521
diff
changeset
|
281 (lambda (line) ;; cleanup extra prompts left in output |
a7740098b594
Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents:
111521
diff
changeset
|
282 (if (string-match |
a7740098b594
Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents:
111521
diff
changeset
|
283 "^\\([ ]*[>+][ ]?\\)+\\([[0-9]+\\|[ ]\\)" line) |
a7740098b594
Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents:
111521
diff
changeset
|
284 (substring line (match-end 1)) |
a7740098b594
Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents:
111521
diff
changeset
|
285 line)) |
a7740098b594
Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents:
111521
diff
changeset
|
286 (org-babel-comint-with-output (session org-babel-R-eoe-output) |
a7740098b594
Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents:
111521
diff
changeset
|
287 (insert (mapconcat #'org-babel-chomp |
a7740098b594
Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents:
111521
diff
changeset
|
288 (list body org-babel-R-eoe-indicator) |
a7740098b594
Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents:
111521
diff
changeset
|
289 "\n")) |
a7740098b594
Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents:
111521
diff
changeset
|
290 (inferior-ess-send-input)))))) "\n")))) |
109462
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
291 |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
292 (defun org-babel-R-process-value-result (result column-names-p) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
293 "R-specific processing of return value. |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
294 Insert hline if column names in output have been requested." |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
295 (if column-names-p |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
296 (cons (car result) (cons 'hline (cdr result))) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
297 result)) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
298 |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
299 (provide 'ob-R) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
300 |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
301 |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
302 ;;; ob-R.el ends here |