* Bug: Babel+R handles spaces wrongly in tables [9.3.6 (release_9.3.6 @ /home/cassou/.emacs.d/lib/org/lisp/)]
@ 2020-09-06 11:32 Damien Cassou
2020-09-06 18:23 ` Berry, Charles via General discussions about Org-mode.
2020-12-19 13:45 ` Jeremie Juste
0 siblings, 2 replies; 7+ messages in thread
From: Damien Cassou @ 2020-09-06 11:32 UTC (permalink / raw)
To: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 662 bytes --]
Hi,
it seems that, if a cell within a table contains a space, the
corresponding value passed as parameter to a R script will be
wrong. Please find a very simple org file attached to this email. I
expect the length of the variable to be 2 (which is the length of '("A
B" "C") and not 3. Apparently, R receives this array instead: '("A B"
"C" nil).
Emacs : GNU Emacs 27.1 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.21, cairo version 1.16.0)
Package: Org mode version 9.3.6 (release_9.3.6 @ /home/cassou/.emacs.d/lib/org/lisp/)
--
Damien Cassou
"Success is the ability to go from one failure to another without
losing enthusiasm." --Winston Churchill
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: test.org --]
[-- Type: text/x-org, Size: 236 bytes --]
#+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
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Bug: Babel+R handles spaces wrongly in tables [9.3.6 (release_9.3.6 @ /home/cassou/.emacs.d/lib/org/lisp/)]
2020-09-06 11:32 Bug: Babel+R handles spaces wrongly in tables [9.3.6 (release_9.3.6 @ /home/cassou/.emacs.d/lib/org/lisp/)] Damien Cassou
@ 2020-09-06 18:23 ` Berry, Charles via General discussions about Org-mode.
2020-09-07 4:40 ` Bastien
2020-12-19 13:45 ` Jeremie Juste
1 sibling, 1 reply; 7+ messages in thread
From: Berry, Charles via General discussions about Org-mode. @ 2020-09-06 18:23 UTC (permalink / raw)
To: Damien Cassou; +Cc: org-mode mailing list
> On Sep 6, 2020, at 4:32 AM, Damien Cassou <damien@cassou.me> wrote:
>
>
> Hi,
>
> it seems that, if a cell within a table contains a space, the
> corresponding value passed as parameter to a R script will be
> wrong.
Not exactly. Your ECM has one column, and using both columns removes the issue.
Here is another ECM that illustrates the bug:
#+begin_src R :results output :var accounts=(identity '("A B" "C"))
print(accounts)
#+end_src
The bug is in `org-babel-R-assign-elisp' which attempts to get the number of elements in each line of a table, but when the table has just one row or column it gets this wrong.
> Please find a very simple org file attached to this email. I
> expect the length of the variable to be 2 (which is the length of '("A
> B" "C") and not 3. Apparently, R receives this array instead: '("A B"
> "C" nil).
>
Actually the length should be 1, i.e. a data.frame with a single column of two elements.
BTW, C-c C-v C-v with point in the src block will show you what R `receives'.
Unfortunately, there are other cases where the variable assignment does not work seamlessly for R src blocks. There are workarounds, but they are ungainly - like using a src block for another language to render the table and then using a noweb reference to it to import the data.
HTH,
Chuck
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Bug: Babel+R handles spaces wrongly in tables [9.3.6 (release_9.3.6 @ /home/cassou/.emacs.d/lib/org/lisp/)]
2020-09-06 11:32 Bug: Babel+R handles spaces wrongly in tables [9.3.6 (release_9.3.6 @ /home/cassou/.emacs.d/lib/org/lisp/)] Damien Cassou
2020-09-06 18:23 ` Berry, Charles via General discussions about Org-mode.
@ 2020-12-19 13:45 ` Jeremie Juste
2021-05-02 3:52 ` Bastien
1 sibling, 1 reply; 7+ messages in thread
From: Jeremie Juste @ 2020-12-19 13:45 UTC (permalink / raw)
To: Damien Cassou, emacs-orgmode; +Cc: Berry, Charles
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 ;-)
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: Bug: Babel+R handles spaces wrongly in tables [9.3.6 (release_9.3.6 @ /home/cassou/.emacs.d/lib/org/lisp/)]
2020-12-19 13:45 ` Jeremie Juste
@ 2021-05-02 3:52 ` Bastien
2021-05-02 22:45 ` Jeremie Juste
0 siblings, 1 reply; 7+ messages in thread
From: Bastien @ 2021-05-02 3:52 UTC (permalink / raw)
To: Jeremie Juste; +Cc: Damien Cassou, Berry, Charles, emacs-orgmode
Hi Damien and Jeremie,
Jeremie Juste <jeremiejuste@gmail.com> writes:
> The following patch will at least harmonize the results towards the
> data.frame.
I see the patch has been applied - thanks!
I'm marking this bug as resolved right now, feel free to reopen it if
I'm wrong.
Thanks,
--
Bastien
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Bug: Babel+R handles spaces wrongly in tables [9.3.6 (release_9.3.6 @ /home/cassou/.emacs.d/lib/org/lisp/)]
2021-05-02 3:52 ` Bastien
@ 2021-05-02 22:45 ` Jeremie Juste
0 siblings, 0 replies; 7+ messages in thread
From: Jeremie Juste @ 2021-05-02 22:45 UTC (permalink / raw)
To: Bastien; +Cc: Damien Cassou, Berry, Charles, emacs-orgmode
Hello Bastien,
Many thanks, I was waiting for feedback but it seems that nobody
complained.
On Sunday, 2 May 2021 at 05:52, Bastien wrote:
> Hi Damien and Jeremie,
>
> Jeremie Juste <jeremiejuste@gmail.com> writes:
>
>> The following patch will at least harmonize the results towards the
>> data.frame.
>
> I see the patch has been applied - thanks!
>
> I'm marking this bug as resolved right now, feel free to reopen it if
> I'm wrong.
>
Thanks, feel free to reopen if you face any issue.
Best regards
--
Jeremie Juste
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2021-05-02 22:46 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-09-06 11:32 Bug: Babel+R handles spaces wrongly in tables [9.3.6 (release_9.3.6 @ /home/cassou/.emacs.d/lib/org/lisp/)] 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
2021-05-02 3:52 ` Bastien
2021-05-02 22:45 ` Jeremie Juste
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).