Explorar o código

babel: allow assigning of variables when preparing R session

This is already in place for other languages, but seems to have been
forgotten for R.
Dan Davison %!s(int64=15) %!d(string=hai) anos
pai
achega
38d6bf3f6c
Modificáronse 1 ficheiros con 9 adicións e 3 borrados
  1. 9 3
      contrib/babel/lisp/langs/org-babel-R.el

+ 9 - 3
contrib/babel/lisp/langs/org-babel-R.el

@@ -59,8 +59,14 @@ called by `org-babel-execute-src-block'."
 (defun org-babel-prep-session:R (session params)
   "Prepare SESSION according to the header arguments specified in PARAMS."
   (let* ((session (org-babel-R-initiate-session session params))
-         (vars (org-babel-ref-variables params)))
-    (mapc (lambda (pair) (org-babel-R-assign-elisp session (car pair) (cdr pair))) vars)
+	 (vars (org-babel-ref-variables params))
+	 (var-lines
+	  (mapcar
+	   (lambda (pair) (org-babel-R-assign-elisp (car pair) (cdr pair))) vars)))
+    (org-babel-comint-in-buffer session
+      (mapc (lambda (var)
+              (move-end-of-line 1) (insert var) (comint-send-input nil t)
+              (org-babel-comint-wait-for-output session)) var-lines))
     session))
 
 (defun org-babel-load-session:R (session body params)
@@ -81,7 +87,7 @@ called by `org-babel-execute-src-block'."
     (format "%S" s)))
 
 (defun org-babel-R-assign-elisp (name value)
-  "Read the elisp VALUE into a variable named NAME."
+  "Construct R code assigning the elisp VALUE to a variable named NAME."
   (if (listp value)
       (let ((transition-file (make-temp-file "org-babel-R-import")))
         ;; ensure VALUE has an orgtbl structure (depth of at least 2)