Browse Source

do not set variables belonging to ESS

* lisp/ob-R.el (org-babel-R-initiate-session): Protect against use of
  unbound variable `ess-ask-for-ess-directory´. The default for this
  variable is true, so act accordingly if it is found unbound.

* lisp/ob-R.el: Remove initialization with `nil´ from
 `ess-ask-for-ess-directory´ and `ess-local-process-name´.  Remove
 second declaration for `ess-local-process-name´.

* testing/lisp/test-ob-R.el (test-ob-R/simple-session): Bind
  `ess-ask-for-ess-directory´ to nil to facilitate batch testing.
Achim Gratz 7 years ago
parent
commit
b20ef32b9a
2 changed files with 8 additions and 7 deletions
  1. 4 4
      lisp/ob-R.el
  2. 4 3
      testing/lisp/test-ob-R.el

+ 4 - 4
lisp/ob-R.el

@@ -76,7 +76,7 @@
   :version "24.1"
   :type 'string)
 
-(defvar ess-local-process-name)
+(defvar ess-local-process-name) ; dynamically scoped
 (defun org-babel-edit-prep:R (info)
   (let ((session (cdr (assoc :session (nth 2 info)))))
     (when (and session (string-match "^\\*\\(.+?\\)\\*$" session))
@@ -201,13 +201,14 @@ This function is called by `org-babel-execute-src-block'."
 		    name file header row-names max))))
     (format "%s <- %s" name (org-babel-R-quote-tsv-field value))))
 
-(defvar ess-ask-for-ess-directory nil)
+(defvar ess-ask-for-ess-directory) ; dynamically scoped
 (defun org-babel-R-initiate-session (session params)
   "If there is not a current R process then create one."
   (unless (string= session "none")
     (let ((session (or session "*R*"))
 	  (ess-ask-for-ess-directory
-	   (and ess-ask-for-ess-directory (not (cdr (assoc :dir params))))))
+	   (and (and (boundp 'ess-ask-for-ess-directory) ess-ask-for-ess-directory)
+		(not (cdr (assoc :dir params))))))
       (if (org-babel-comint-buffer-livep session)
 	  session
 	(save-window-excursion
@@ -220,7 +221,6 @@ This function is called by `org-babel-execute-src-block'."
 	       (buffer-name))))
 	  (current-buffer))))))
 
-(defvar ess-local-process-name nil)
 (defun org-babel-R-associate-session (session)
   "Associate R code buffer with an R session.
 Make SESSION be the inferior ESS process associated with the

+ 4 - 3
testing/lisp/test-ob-R.el

@@ -14,9 +14,10 @@
   (signal 'missing-test-dependency "Support for R code blocks"))
 
 (ert-deftest test-ob-R/simple-session ()
-  (org-test-with-temp-text
-      "#+begin_src R :session R\n  paste(\"Yep!\")\n#+end_src\n"
-    (should (string= "Yep!" (org-babel-execute-src-block)))))
+  (let ((ess-ask-for-ess-directory nil))
+    (org-test-with-temp-text
+     "#+begin_src R :session R\n  paste(\"Yep!\")\n#+end_src\n"
+     (should (string= "Yep!" (org-babel-execute-src-block))))))
 
 (ert-deftest test-ob-R/colnames-yes-header-argument ()
   (org-test-with-temp-text "#+name: eg