From 662e814bc067153c74aeba5f882d547e327db8b4 Mon Sep 17 00:00:00 2001 From: Jeremie Juste Date: Wed, 7 Dec 2022 21:25:19 +0100 Subject: [PATCH] ob-R.el: Restore the handling of org-list in as var * ob-R.el (org-babel-R-assign-elisp): Use the patch from ccberry@health.ucsd.edu, to print org-list as a one column table as it was the case in release_9.5. The break in R is due commit b4e437f96 * ob-core: Resolve named list references to simple lists. * test-ob-R.el (ob-R-nested-list): New function to test that org list with multiple level are handled as expected in R. see https://list.orgmode.org/87bkofh0ir.fsf@localhost/ for context. --- lisp/ob-R.el | 4 ++-- testing/lisp/test-ob-R.el | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/lisp/ob-R.el b/lisp/ob-R.el index f68b5b44e..b7f96a179 100644 --- a/lisp/ob-R.el +++ b/lisp/ob-R.el @@ -241,11 +241,11 @@ This function is called by `org-babel-execute-src-block'." (defun org-babel-R-assign-elisp (name value colnames-p rownames-p) "Construct R code assigning the elisp VALUE to a variable named NAME." (if (listp value) - (let* ((lengths (mapcar 'length (cl-remove-if-not 'sequencep value))) + (let* ((lengths (mapcar 'length (cl-remove-if-not 'listp value))) (max (if lengths (apply 'max lengths) 0)) (min (if lengths (apply 'min lengths) 0))) ;; Ensure VALUE has an orgtbl structure (depth of at least 2). - (unless (listp (car value)) (setq value (list value))) + (unless (listp (car value)) (setq value (mapcar 'list value))) (let ((file (orgtbl-to-tsv value '(:fmt org-babel-R-quote-tsv-field))) (header (if (or (eq (nth 1 value) 'hline) colnames-p) "TRUE" "FALSE")) diff --git a/testing/lisp/test-ob-R.el b/testing/lisp/test-ob-R.el index da142fb3c..cbd5a36a2 100644 --- a/testing/lisp/test-ob-R.el +++ b/testing/lisp/test-ob-R.el @@ -261,6 +261,41 @@ log10(10) (string= (concat src-block result) (buffer-string))))))) + +;; test for printing of (nested) list +(ert-deftest ob-R-nested-list () + "List are printed as the first column of a table and nested lists are ignored" + (let (ess-ask-for-ess-directory + ess-history-file + org-confirm-babel-evaluate + (org-babel-temporary-directory "/tmp") + (text " +#+NAME: example-list +- simple + - not + - nested +- list + +#+BEGIN_SRC R :var x=example-list +x +#+END_SRC +") +(result " +#+RESULTS: +| simple | +| list | +")) +(org-test-with-temp-text-in-file + text + (goto-char (point-min)) + (org-babel-next-src-block) + (should (progn + (org-babel-execute-src-block) + (sleep-for 0 200) + (string= (concat text result) + (buffer-string))))))) + + (provide 'test-ob-R) ;;; test-ob-R.el ends here