mirror of
https://git.savannah.gnu.org/git/emacs/org-mode.git
synced 2024-09-30 00:57:48 +00:00
fixed non-session variable assignment in R
This commit is contained in:
parent
a44c98b376
commit
112c7d9236
|
@ -39,21 +39,24 @@ called by `org-babel-execute-src-block'."
|
||||||
(message "executing R source code block...")
|
(message "executing R source code block...")
|
||||||
(save-window-excursion
|
(save-window-excursion
|
||||||
(let* ((vars (org-babel-ref-variables params))
|
(let* ((vars (org-babel-ref-variables params))
|
||||||
|
(full-body (concat
|
||||||
|
(mapconcat ;; define any variables
|
||||||
|
(lambda (pair)
|
||||||
|
(org-babel-R-assign-elisp (car pair) (cdr pair)))
|
||||||
|
vars "\n") "\n" body "\n"))
|
||||||
(result-params (split-string (or (cdr (assoc :results params)) "")))
|
(result-params (split-string (or (cdr (assoc :results params)) "")))
|
||||||
(result-type (cond ((member "output" result-params) 'output)
|
(result-type (cond ((member "output" result-params) 'output)
|
||||||
((member "value" result-params) 'value)
|
((member "value" result-params) 'value)
|
||||||
(t 'value)))
|
(t 'value)))
|
||||||
(session (org-babel-R-initiate-session (cdr (assoc :session params))))
|
(session (org-babel-R-initiate-session (cdr (assoc :session params))))
|
||||||
results)
|
results)
|
||||||
;; assign variables
|
|
||||||
(mapc (lambda (pair) (org-babel-R-assign-elisp session (car pair) (cdr pair))) vars)
|
|
||||||
;; ;;; debugging statements
|
;; ;;; debugging statements
|
||||||
;; (message (format "result-type=%S" result-type))
|
;; (message (format "result-type=%S" result-type))
|
||||||
;; (message (format "body=%S" body))
|
;; (message (format "body=%S" body))
|
||||||
;; (message (format "session=%S" session))
|
;; (message (format "session=%S" session))
|
||||||
;; (message (format "result-params=%S" result-params))
|
;; (message (format "result-params=%S" result-params))
|
||||||
;; evaluate body and convert the results to ruby
|
;; evaluate body and convert the results to ruby
|
||||||
(setq results (org-babel-R-evaluate session body result-type))
|
(setq results (org-babel-R-evaluate session full-body result-type))
|
||||||
(setq results (if (member "scalar" result-params)
|
(setq results (if (member "scalar" result-params)
|
||||||
results
|
results
|
||||||
(let ((tmp-file (make-temp-file "org-babel-R")))
|
(let ((tmp-file (make-temp-file "org-babel-R")))
|
||||||
|
@ -77,22 +80,18 @@ called by `org-babel-execute-src-block'."
|
||||||
(concat "\"" (mapconcat 'identity (split-string s "\"") "\"\"") "\"")
|
(concat "\"" (mapconcat 'identity (split-string s "\"") "\"\"") "\"")
|
||||||
(format "%S" s)))
|
(format "%S" s)))
|
||||||
|
|
||||||
(defun org-babel-R-assign-elisp (session name value)
|
(defun org-babel-R-assign-elisp (name value)
|
||||||
"Read the elisp VALUE into a variable named NAME in the current
|
"Read the elisp VALUE into a variable named NAME."
|
||||||
R process in `org-babel-R-buffer'."
|
(if (listp value)
|
||||||
(unless session (error "No active R buffer"))
|
(let ((transition-file (make-temp-file "org-babel-R-import")))
|
||||||
(org-babel-comint-input-command
|
;; ensure VALUE has an orgtbl structure (depth of at least 2)
|
||||||
session
|
(unless (listp (car value)) (setq value (list value)))
|
||||||
(if (listp value)
|
(with-temp-file transition-file
|
||||||
(let ((transition-file (make-temp-file "org-babel-R-import")))
|
(insert (orgtbl-to-tsv value '(:fmt org-babel-R-quote-tsv-field)))
|
||||||
;; ensure VALUE has an orgtbl structure (depth of at least 2)
|
(insert "\n"))
|
||||||
(unless (listp (car value)) (setq value (list value)))
|
(format "%s <- read.table(\"%s\", header=FALSE, sep=\"\\t\", as.is=TRUE)"
|
||||||
(with-temp-file transition-file
|
name transition-file))
|
||||||
(insert (orgtbl-to-tsv value '(:fmt org-babel-R-quote-tsv-field)))
|
(format "%s <- %s" name (org-babel-R-quote-tsv-field value))))
|
||||||
(insert "\n"))
|
|
||||||
(format "%s <- read.table(\"%s\", header=FALSE, sep=\"\\t\", as.is=TRUE)"
|
|
||||||
name transition-file))
|
|
||||||
(format "%s <- %s" name (org-babel-R-quote-tsv-field value)))))
|
|
||||||
|
|
||||||
(defun org-babel-R-initiate-session (session)
|
(defun org-babel-R-initiate-session (session)
|
||||||
"If there is not a current R process then create one."
|
"If there is not a current R process then create one."
|
||||||
|
|
|
@ -2218,52 +2218,52 @@ org-babel functionality.
|
||||||
of these tests may fail.
|
of these tests may fail.
|
||||||
|
|
||||||
#+TBLNAME: org-babel-tests
|
#+TBLNAME: org-babel-tests
|
||||||
| functionality | block | arg | expected | results | pass |
|
| functionality | block | arg | expected | results | pass |
|
||||||
|-------------------------+----------------------------+-----+-------------+-------------+---------------------------------|
|
|-------------------------+----------------------------+-----+-------------+-------------+----------------------------|
|
||||||
| basic evaluation | | | | | pass |
|
| basic evaluation | | | | | pass |
|
||||||
|-------------------------+----------------------------+-----+-------------+-------------+---------------------------------|
|
|-------------------------+----------------------------+-----+-------------+-------------+----------------------------|
|
||||||
| emacs lisp | basic-elisp | | 5 | 5 | pass |
|
| emacs lisp | basic-elisp | | 5 | 5 | pass |
|
||||||
| shell | basic-shell | | 6 | 6 | pass |
|
| shell | basic-shell | | 6 | 6 | pass |
|
||||||
| ruby | basic-ruby | | org-babel | org-babel | pass |
|
| ruby | basic-ruby | | org-babel | org-babel | pass |
|
||||||
| python | basic-python | | hello world | hello world | pass |
|
| python | basic-python | | hello world | hello world | pass |
|
||||||
| R | basic-R | | 13 | 13 | pass |
|
| R | basic-R | | 13 | 13 | pass |
|
||||||
|-------------------------+----------------------------+-----+-------------+-------------+---------------------------------|
|
|-------------------------+----------------------------+-----+-------------+-------------+----------------------------|
|
||||||
| tables | | | | | pass |
|
| tables | | | | | pass |
|
||||||
|-------------------------+----------------------------+-----+-------------+-------------+---------------------------------|
|
|-------------------------+----------------------------+-----+-------------+-------------+----------------------------|
|
||||||
| emacs lisp | table-elisp | | 3 | 3 | pass |
|
| emacs lisp | table-elisp | | 3 | 3 | pass |
|
||||||
| ruby | table-ruby | | 1-2-3 | 1-2-3 | pass |
|
| ruby | table-ruby | | 1-2-3 | 1-2-3 | pass |
|
||||||
| python | table-python | | 5 | 5 | pass |
|
| python | table-python | | 5 | 5 | pass |
|
||||||
| R | table-R | | 3.5 | #ERROR | expected "3.5" but was "#ERROR" |
|
| R | table-R | | 3.5 | 3.5 | pass |
|
||||||
|-------------------------+----------------------------+-----+-------------+-------------+---------------------------------|
|
|-------------------------+----------------------------+-----+-------------+-------------+----------------------------|
|
||||||
| source block references | | | | | pass |
|
| source block references | | | | | pass |
|
||||||
|-------------------------+----------------------------+-----+-------------+-------------+---------------------------------|
|
|-------------------------+----------------------------+-----+-------------+-------------+----------------------------|
|
||||||
| all languages | chained-ref-last | | Array | Array | pass |
|
| all languages | chained-ref-last | | Array | Array | pass |
|
||||||
|-------------------------+----------------------------+-----+-------------+-------------+---------------------------------|
|
|-------------------------+----------------------------+-----+-------------+-------------+----------------------------|
|
||||||
| source block functions | | | | | pass |
|
| source block functions | | | | | pass |
|
||||||
|-------------------------+----------------------------+-----+-------------+-------------+---------------------------------|
|
|-------------------------+----------------------------+-----+-------------+-------------+----------------------------|
|
||||||
| emacs lisp | defun-fibb | | fibbd | fibbd | pass |
|
| emacs lisp | defun-fibb | | fibbd | fibbd | pass |
|
||||||
| run over | Fibonacci | 0 | 1 | 1 | pass |
|
| run over | Fibonacci | 0 | 1 | 1 | pass |
|
||||||
| a | Fibonacci | 1 | 1 | 1 | pass |
|
| a | Fibonacci | 1 | 1 | 1 | pass |
|
||||||
| variety | Fibonacci | 2 | 2 | 2 | pass |
|
| variety | Fibonacci | 2 | 2 | 2 | pass |
|
||||||
| of | Fibonacci | 3 | 3 | 3 | pass |
|
| of | Fibonacci | 3 | 3 | 3 | pass |
|
||||||
| different | Fibonacci | 4 | 5 | 5 | pass |
|
| different | Fibonacci | 4 | 5 | 5 | pass |
|
||||||
| arguments | Fibonacci | 5 | 8 | 8 | pass |
|
| arguments | Fibonacci | 5 | 8 | 8 | pass |
|
||||||
|-------------------------+----------------------------+-----+-------------+-------------+---------------------------------|
|
|-------------------------+----------------------------+-----+-------------+-------------+----------------------------|
|
||||||
| bugs and tasks | | | | | pass |
|
| bugs and tasks | | | | | pass |
|
||||||
|-------------------------+----------------------------+-----+-------------+-------------+---------------------------------|
|
|-------------------------+----------------------------+-----+-------------+-------------+----------------------------|
|
||||||
| simple ruby arrays | ruby-array-test | | 3 | 3 | pass |
|
| simple ruby arrays | ruby-array-test | | 3 | 3 | pass |
|
||||||
| R number evaluation | bug-R-number-evaluation | | 2 | #ERROR | expected "2" but was "#ERROR" |
|
| R number evaluation | bug-R-number-evaluation | | 2 | 2 | pass |
|
||||||
| multi-line ruby blocks | multi-line-ruby-test | | 2 | 2 | pass |
|
| multi-line ruby blocks | multi-line-ruby-test | | 2 | 2 | pass |
|
||||||
| forcing vector results | test-forced-vector-results | | Array | Array | pass |
|
| forcing vector results | test-forced-vector-results | | Array | Array | pass |
|
||||||
|-------------------------+----------------------------+-----+-------------+-------------+---------------------------------|
|
|-------------------------+----------------------------+-----+-------------+-------------+----------------------------|
|
||||||
| sessions | | | | | pass |
|
| sessions | | | | | pass |
|
||||||
|-------------------------+----------------------------+-----+-------------+-------------+---------------------------------|
|
|-------------------------+----------------------------+-----+-------------+-------------+----------------------------|
|
||||||
| set ruby session | set-ruby-session-var | | :set | :set | pass |
|
| set ruby session | set-ruby-session-var | | :set | :set | pass |
|
||||||
| get from ruby session | get-ruby-session-var | | 3 | | expected "3" but was "" |
|
| get from ruby session | get-ruby-session-var | | 3 | | expected "3" but was "" |
|
||||||
| set python session | set-python-session-var | | set | set | pass |
|
| set python session | set-python-session-var | | set | set | pass |
|
||||||
| get from python session | get-python-session-var | | 4 | | expected "4" but was "" |
|
| get from python session | get-python-session-var | | 4 | | expected "4" but was "" |
|
||||||
| set R session | set-R-session-var | | set | set | pass |
|
| set R session | set-R-session-var | | set | set | pass |
|
||||||
| get from R session | get-R-session-var | | 5 | nil | expected "5" but was "nil" |
|
| get from R session | get-R-session-var | | 5 | nil | expected "5" but was "nil" |
|
||||||
#+TBLFM: $5='(if (= (length $3) 1) (progn (message (format "running %S" '(sbe $2 (n $3)))) (sbe $2 (n $3))) (sbe $2))::$6='(if (string= $4 $5) "pass" (format "expected %S but was %S" $4 $5))
|
#+TBLFM: $5='(if (= (length $3) 1) (progn (message (format "running %S" '(sbe $2 (n $3)))) (sbe $2 (n $3))) (sbe $2))::$6='(if (string= $4 $5) "pass" (format "expected %S but was %S" $4 $5))
|
||||||
|
|
||||||
** basic tests
|
** basic tests
|
||||||
|
|
Loading…
Reference in a new issue