Explorar el Código

ob-R.el: Trim extraneous newline from results

* lisp/ob-R.el: org-babel-R-evaluate-external-process and
  org-babel-R-evaluate-session trim the extraneous newlines from the
  end of R output.

* testing/lisp/test-ob-R.el: test-ob-R/results-file tests that
  `:results file' yields one line enclosed in square brackets for a
  result like "abc/def.ghi".

Fixes issue noted by Andreas Leha
Subject: [babel] return file from R
Archived-At: <http://permalink.gmane.org/gmane.emacs.orgmode/103658>
Charles Berry hace 9 años
padre
commit
3142d139fa
Se han modificado 2 ficheros con 18 adiciones y 2 borrados
  1. 2 2
      lisp/ob-R.el
  2. 16 0
      testing/lisp/test-ob-R.el

+ 2 - 2
lisp/ob-R.el

@@ -397,7 +397,7 @@ last statement in BODY, as elisp."
 	(org-babel-result-cond result-params
 	  (with-temp-buffer
 	    (insert-file-contents tmp-file)
-	    (buffer-string))
+	    (org-babel-chomp (buffer-string) "\n"))
 	  (org-babel-import-elisp-from-file tmp-file '(16)))
 	column-names-p)))
     (output (org-babel-eval org-babel-R-command body))))
@@ -431,7 +431,7 @@ last statement in BODY, as elisp."
 	(org-babel-result-cond result-params
 	  (with-temp-buffer
 	    (insert-file-contents tmp-file)
-	    (buffer-string))
+	    (org-babel-chomp (buffer-string) "\n"))
 	  (org-babel-import-elisp-from-file tmp-file '(16)))
 	column-names-p)))
     (output

+ 16 - 0
testing/lisp/test-ob-R.el

@@ -79,6 +79,22 @@ x
     (should (equal '(("col") ("a") ("b"))
 		   (org-babel-execute-src-block)))))
 
+(ert-deftest test-ob-R/results-file ()
+  (org-test-with-temp-text "#+NAME: TESTSRC
+#+BEGIN_SRC R :results file
+  a <- file.path(\"junk\", \"test.org\")
+  a
+#+END_SRC"
+    (goto-char (point-min)) (org-babel-execute-maybe)
+    (org-babel-goto-named-result "TESTSRC") (forward-line 1)
+    (should (string= "[[file:junk/test.org]]"
+		     (buffer-substring-no-properties (point-at-bol) (point-at-eol))))
+    (goto-char (point-min)) (forward-line 1)
+    (insert "#+header: :session\n")
+    (goto-char (point-min)) (org-babel-execute-maybe)
+    (org-babel-goto-named-result "TESTSRC") (forward-line 1)
+    (should (string= "[[file:junk/test.org]]"
+		     (buffer-substring-no-properties (point-at-bol) (point-at-eol))))))
 (provide 'test-ob-R)
 
 ;;; test-ob-R.el ends here