Function: org-babel-R-evaluate-session

org-babel-R-evaluate-session is a byte-compiled function defined in ob-R.el.gz.

Signature

(org-babel-R-evaluate-session SESSION BODY RESULT-TYPE RESULT-PARAMS COLUMN-NAMES-P ROW-NAMES-P)

Documentation

Evaluate BODY in SESSION.

If RESULT-TYPE equals output then return standard output as a string. If RESULT-TYPE equals value then return the value of the last statement in BODY, as elisp.

Source Code

;; Defined in /usr/src/emacs/lisp/org/ob-R.el.gz
(defun org-babel-R-evaluate-session
    (session body result-type result-params column-names-p row-names-p)
  "Evaluate BODY in SESSION.
If RESULT-TYPE equals `output' then return standard output as a
string.  If RESULT-TYPE equals `value' then return the value of the
last statement in BODY, as elisp."
  (cl-case result-type
    (value
     (with-temp-buffer
       (insert (org-babel-chomp body))
       (let ((ess-local-process-name
	      (process-name (get-buffer-process session)))
	     (ess-eval-visibly-p nil))
	 (ess-eval-buffer nil)))
     (let ((tmp-file (org-babel-temp-file "R-")))
       (org-babel-comint-eval-invisibly-and-wait-for-file
	session tmp-file
	(format org-babel-R-write-object-command
		(if row-names-p "TRUE" "FALSE")
		(if column-names-p
		    (if row-names-p "NA" "TRUE")
		  "FALSE")
		".Last.value" (org-babel-process-file-name tmp-file 'noquote)))
       (org-babel-R-process-value-result
	(org-babel-result-cond result-params
	  (with-temp-buffer
	    (insert-file-contents tmp-file)
	    (org-babel-chomp (buffer-string) "\n"))
	  (org-babel-import-elisp-from-file tmp-file '(16)))
	column-names-p)))
    (output
     (let ((tmp-src-file (org-babel-temp-file "R-")))
       (with-temp-file tmp-src-file
         (insert (concat
                  (org-babel-chomp body) "\n" org-babel-R-eoe-indicator)))
       (with-current-buffer session
         (org-babel-chomp
          (string-trim-right
           (org-babel-comint-with-output
             (session org-babel-R-eoe-output nil nil 'disable-prompt-filtering)
           (ess-send-string (get-buffer-process (current-buffer))
                            (format "source('%s', echo=F, print.eval=T)"
                                    (org-babel-process-file-name
                                     tmp-src-file 'noquote))))
           (rx (literal org-babel-R-eoe-output) (zero-or-more anychar)))))))))