Re: [O] bug: orgtbl-to-tsv: premature end of table

2015-07-23 Thread Andreas Leha
Hi all,

"Charles C. Berry"  writes:
> On Wed, 22 Jul 2015, Nicolas Goaziou wrote:
>
>> Hello,
>>
>> "Charles C. Berry"  writes:
>>
>>> Not a bug IMO.
>>
>> Notwithstanding the R issue, I think trimming the output of a radio
>> table is a bit aggressive. We cannot know if trailing (and leading)
>> spaces are significant in the output format the user defined.
>>
>> I removed the trimming part in commit
>> bf37cd09b128b4431e1dd1a538fbcc4be3615042.
>>
>> Let me know if you disagree with that change.
>
> I don't think the change broke anything that wasn't already broken.
>
> And my diagnosis was wrong - I was confused by a problem that remains:
>
> `org-babel-R-assign-elisp' is broken. Ragged rows in a table are filled 
> with "" in each missing field; `org-table-to-lisp' returns a list of lists 
> of common length.
>
> `org-babel-R-assign-elisp' inspects that list to see if any element vary 
> in length. But they do not, and therefore `max' and `min' in the let* 
> varlist are equal and later on `ob-R-transfer-variable-table-with-header' 
> is always used.
>
> I think lom pik's example would not have failed had max and min differed 
> as `ob-R-transfer-variable-table-without-header' would have been used 
> instead.
>
> R src blocks ought to render missing elements due to ragged rows in a 
> table as NA, but this isnt the current behavior for this table:
>
> #+NAME: tbl-ragged
> | 1 | 2 | a |
>
> | 8 | 9 |   |
>
> It seems like the fix for this would be to prune any "" at the ends of 
> lists in the value arg when beginning  `org-babel-R-assign-elisp'.
>
> But I am tired, so I'll defer trying this till another time.
>
> Best,
>
> Chuck

Thank you all for looking into this.  I have seen this as well and the
manual work-around (to put sth into the last cell) was getting really
annoying -- especially if the table was auto-generated by sth else.

While looking at handling tables, could I suggest to switch to csv
instead of tsv for the table passing?  I still see issues with tables
not separated.  (This happens only in preview (C-c C-v v) and not when
executing the block.)  I never had time to track this down, but I get
caught now and then.  Using csv should be more robust in this regard.

Thanks,
Andreas




Re: [O] bug: orgtbl-to-tsv: premature end of table

2015-07-22 Thread Charles C. Berry

On Wed, 22 Jul 2015, Nicolas Goaziou wrote:


Hello,

"Charles C. Berry"  writes:


Not a bug IMO.


Notwithstanding the R issue, I think trimming the output of a radio
table is a bit aggressive. We cannot know if trailing (and leading)
spaces are significant in the output format the user defined.

I removed the trimming part in commit
bf37cd09b128b4431e1dd1a538fbcc4be3615042.

Let me know if you disagree with that change.


I don't think the change broke anything that wasn't already broken.

And my diagnosis was wrong - I was confused by a problem that remains:

`org-babel-R-assign-elisp' is broken. Ragged rows in a table are filled 
with "" in each missing field; `org-table-to-lisp' returns a list of lists 
of common length.


`org-babel-R-assign-elisp' inspects that list to see if any element vary 
in length. But they do not, and therefore `max' and `min' in the let* 
varlist are equal and later on `ob-R-transfer-variable-table-with-header' 
is always used.


I think lom pik's example would not have failed had max and min differed 
as `ob-R-transfer-variable-table-without-header' would have been used 
instead.


R src blocks ought to render missing elements due to ragged rows in a 
table as NA, but this isnt the current behavior for this table:


#+NAME: tbl-ragged
| 1 | 2 | a |
| 8 | 9 |   |

It seems like the fix for this would be to prune any "" at the ends of 
lists in the value arg when beginning  `org-babel-R-assign-elisp'.


But I am tired, so I'll defer trying this till another time.

Best,

Chuck



Re: [O] bug: orgtbl-to-tsv: premature end of table

2015-07-22 Thread lom pik
Hi

> removed the trimming part in commit
> bf37cd09b128b4431e1dd1a538fbcc4be3615042.

With this commit, issue is gone. This did not happen in previous org-mode
releases although all other proposed workarounds worked as well.

Regards.
lompik

On Wed, Jul 22, 2015 at 5:41 PM, Nicolas Goaziou 
wrote:

> Hello,
>
> "Charles C. Berry"  writes:
>
> > Not a bug IMO.
>
> Notwithstanding the R issue, I think trimming the output of a radio
> table is a bit aggressive. We cannot know if trailing (and leading)
> spaces are significant in the output format the user defined.
>
> I removed the trimming part in commit
> bf37cd09b128b4431e1dd1a538fbcc4be3615042.
>
> Let me know if you disagree with that change.
>
>
> Regards,
>
> --
> Nicolas Goaziou
>


Re: [O] bug: orgtbl-to-tsv: premature end of table

2015-07-22 Thread Nicolas Goaziou
Hello,

"Charles C. Berry"  writes:

> Not a bug IMO.

Notwithstanding the R issue, I think trimming the output of a radio
table is a bit aggressive. We cannot know if trailing (and leading)
spaces are significant in the output format the user defined.

I removed the trimming part in commit
bf37cd09b128b4431e1dd1a538fbcc4be3615042.

Let me know if you disagree with that change.


Regards,

-- 
Nicolas Goaziou



Re: [O] bug: orgtbl-to-tsv: premature end of table

2015-07-22 Thread Charles C. Berry

On Tue, 14 Jul 2015, lom pik wrote:


Hi,

-- this was only tested with the current git version

I was trying to export a table as a variable to R via babel evaluation.
However it seems that is the rows are empty , the exported table ends at
the last non-empty value.

For example,the second row of tbl-issue defined below ends with 2 columns
[8,9]. The next table however works ok. I've narrowed down the cause to the
orgtbl-to-tsv function as highlighted below.


Not a bug IMO.

See the R documentation page for `read.table'. Note `fill'.



#+NAME: tbl-issue
| 1 | 2 | 3 | 5 | 6 | 7 |
| 8 | 9 |   |   |   |   |
#+BEGIN_SRC R :session *R* :var df2=tbl-issue  :results value## won't
work
print(df2)
#+END_SRC


You have two options (at least):

1. Place `NA' in the last cell of the last line

2. add ' , fill=TRUE ' like this:

#+BEGIN_SRC emacs-lisp
  (setq
   ob-R-transfer-variable-table-with-header
   "%s <- local({
   con <- textConnection(
 %S
   )
   res <- utils::read.table(
 con,
 header= %s,
 row.names = %s,
 sep   = \"\\t\",
 as.is = TRUE, fill=TRUE
   )
   close(con)
   res
 })")
#+END_SRC


Either way you will get:

#+RESULTS:
| 1 | 2 |   3 |   5 |   6 |   7 |
| 8 | 9 | nil | nil | nil | nil |


HTH,

Chuck




[O] bug: orgtbl-to-tsv: premature end of table

2015-07-22 Thread lom pik
Hi,

-- this was only tested with the current git version

I was trying to export a table as a variable to R via babel evaluation.
However it seems that is the rows are empty , the exported table ends at
the last non-empty value.

For example,the second row of tbl-issue defined below ends with 2 columns
[8,9]. The next table however works ok. I've narrowed down the cause to the
orgtbl-to-tsv function as highlighted below.

#+NAME: tbl-issue
| 1 | 2 | 3 | 5 | 6 | 7 |
| 8 | 9 |   |   |   |   |
#+BEGIN_SRC R :session *R* :var df2=tbl-issue  :results value## won't
work
print(df2)
#+END_SRC

 (orgtbl-to-tsv '( (1 2 #1="" #1# #1# #1# ) ) '(:fmt
org-babel-R-quote-tsv-field))   ->   "\"1\"\"2\""



#+NAME: tlb-ok
| 1 | 2 | 3 | 5 | 6 | 7 |
| 8 | 9 |   |   |   | 10  |
#+BEGIN_SRC R :session *R* :var df2=tbl-ok  :results value  # work ok
print(df2)
#+END_SRC

 (orgtbl-to-tsv '( (1 2 #1="" #1# #1# #1# 10) ) '(:fmt
org-babel-R-quote-tsv-field))  ->
"\"1\"\"2\"\"1\""



Emacs 24.5 with Org-mode version 8.3beta
(release_8.3beta-1286-g20795f.dirty )

Regards,
lompik


[O] [BUG] orgtbl-to-tsv: premature end of table

2015-07-22 Thread lom pik
Hi,

-- this was only tested with the git version

I was trying to export a table as a variable to R via babel evaluation.
However it seems that is the rows are empty , the exported table ends at
the last non-empty value.

For example,the second row of tbl-issue defined below ends with 2 columns
[8,9]. The next table however works ok. I've narrowed down the cause to the
orgtbl-to-tsv function as highlighted below.

#+NAME: tbl-issue
| 1 | 2 | 3 | 5 | 6 | 7 |
| 8 | 9 |   |   |   |   |
#+BEGIN_SRC R :session *R* :var df2=tbl-issue  :results value## won't
work
print(df2)
#+END_SRC

 (orgtbl-to-tsv '( (1 2 #1="" #1# #1# #1# ) ) '(:fmt
org-babel-R-quote-tsv-field))   ->   "\"1\"\"2\""



#+NAME: tlb-ok
| 1 | 2 | 3 | 5 | 6 | 7 |
| 8 | 9 |   |   |   | 10  |
#+BEGIN_SRC R :session *R* :var df2=tbl-ok  :results value  # work ok
print(df2)
#+END_SRC

 (orgtbl-to-tsv '( (1 2 #1="" #1# #1# #1# 10) ) '(:fmt
org-babel-R-quote-tsv-field))  ->
"\"1\"\"2\"\"1\""



Emacs 24.5 with Org-mode version 8.3beta
(release_8.3beta-1286-g20795f.dirty )

Regards,
lompik