Org-mode mailing list
 help / color / mirror / Atom feed
From: Jeremie Juste <jeremiejuste@gmail.com>
To: Damien Cassou <damien@cassou.me>, emacs-orgmode@gnu.org
Cc: "Berry, Charles" <ccberry@health.ucsd.edu>
Subject: Re: Bug: Babel+R handles spaces wrongly in tables [9.3.6 (release_9.3.6 @ /home/cassou/.emacs.d/lib/org/lisp/)]
Date: Sat, 19 Dec 2020 14:45:46 +0100
Message-ID: <87mty99aet.fsf@gmail.com> (raw)
In-Reply-To: <87wo172laf.fsf@cassou.me>

Hello,

Apologies for the late reply and thanks for pointing out this bug.
|| On Sunday,  6 Sep 2020 at 13:32, Damien Cassou wrote:

#+name: table
|     | 2014 |
|-----+------|
| A C |    1 |
| C   |    2 |

#+name: linechart
#+begin_src R :results value :var accounts="" :exports none
length(accounts)
#+end_src

#+call: linechart(accounts=table[,0])

#+RESULTS:
: 3

Currently there are no support for vectors. So it is either a
data.frame or an object of length 1. 

|| On Sun, 06 Sep 2020 18:23:19  Berry, Charles" wrote
> Actually the length should be 1, i.e. a data.frame with a single column of two elements.

Indeed with the current handling the length should be 1 but it is
not. Even with the previous case solved, it might still be an
unexpected behavior for a typical R user who would expect a vector. Do you
think it is reasonable?

The following patch will at least harmonize the results towards the
data.frame. 

diff --git a/lisp/ob-R.el b/lisp/ob-R.el
index 420b8ccbc..81693d157 100644
--- a/lisp/ob-R.el
+++ b/lisp/ob-R.el
@@ -236,11 +236,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* ((value (if (listp (car value)) value (list value)))
-            (lengths (mapcar 'length (cl-remove-if-not 'sequencep value)))
+      (let* ((lengths (mapcar 'length (cl-remove-if-not 'sequencep 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)))
        (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"))


so the following will return a data.frame

#+begin_src R :results output :var accounts=(identity '("A B" "C")) 
print(accounts)
#+end_src

#+RESULTS:
:    V1 V2
: 1 A B  C


I will add support for selection of 1 single column as a
vector soon.

Best regards,
Jeremie

PS: I am a newbie maintainer so feel free to comment if there you find
room for improvements ;-)


  parent reply	other threads:[~2020-12-19 13:46 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-06 11:32 Damien Cassou
2020-09-06 18:23 ` Berry, Charles via General discussions about Org-mode.
2020-09-07  4:40   ` Bastien
2020-09-07  4:44     ` Bastien
2020-12-19 13:45 ` Jeremie Juste [this message]
2021-05-02  3:52   ` Bastien
2021-05-02 22:45     ` Jeremie Juste

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://orgmode.org

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87mty99aet.fsf@gmail.com \
    --to=jeremiejuste@gmail.com \
    --cc=ccberry@health.ucsd.edu \
    --cc=damien@cassou.me \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Org-mode mailing list

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://orgmode.org/list/0 list/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 list list/ https://orgmode.org/list \
		emacs-orgmode@gnu.org
	public-inbox-index list

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.yhetil.org/yhetil.emacs.orgmode
	nntp://news.gmane.io/gmane.emacs.orgmode


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git