Re: How to retrieve ALL the information of an Org table ?

2021-10-09 Thread Ihor Radchenko
Emmanuel Charpentier  writes:

> Passing this table as an argument to source code loses the hlines :
> #+begin_src emacs-lisp :exports results :results drawer :var foo=ttest
> foo
> #+end_src

I think you are looking for ":hlines yes" header arg (the default is no)

Best,
Ihor



How to retrieve ALL the information of an Org table ?

2021-10-09 Thread Emmanuel Charpentier
Dear list,
I have problems with exploiting programatically the structure of an Org
table :
I want to write function acting on complex tables, where the original
information is presented along various statistics. My idea is to
isolate the original information in a range delimited (by convention)
by the first and second hlines and by the first and last columns ; the
function should accept the whole table and retrieve the original
data. The point is that the function should accept a variable number of
lines in both the "original data" range and the summary information.
Let ttest such a table with hlines :
#+name: ttest
| ttest | c1 | c2 | rSum |
|---+++--|
| 3 | 3 | 5 | 8 |
| 8 | 8 | 12 | 20 |
|---+++--|
| cSum | 11 | 17 | 28 |
#+TBLFM: @>$2..@>$>=vsum(@I..@II)::@2..@>>$4=vsum($<<..$>>)
ttestc1c2rSum3358881220cSum111728
Passing this table as an argument to source code loses the hlines :
#+begin_src emacs-lisp :exports results :results drawer :var foo=ttest
foo
#+end_src
((ttest c1 c2 rSum) (3 3 5 8) (8 8 12 20) (cSum 11 17 28))
The structure allowing to retrieve the original data is lost.
The point is that the source code can't exploit the hlines to find
relevant information (in the present case, the lines between the
hlines).
Alternatively, one may try and pass the relevant range, using foo=(org-
table-get-remote-range "ttest" "@I$<<..@II$>>") as an argument. This
fails for a different reason :
#+begin_src emacs-lisp :exports results :results drawer :var foo=(org-
table-get-remote-range "ttest" "@I$<<..@II$>>")
foo
#+end_src
(3 5 8 12)
Again, the structure is lost : this time, foo is a "flattened" vector,
whose matricial shape is lost to the processing function.
I am looking for explanations and/or hints.

Attached : the source of the present mail.

Thanks in advance...

--
Emmanuel Charpentier

#+options: author:nil toc:nil
#+property: header-args:python :session
# #+latex_header: \usepackage{minted}

#+begin_src emacs-lisp :exports none
  (setq org-odt-preferred-output-format "docx"
org-latex-to-mathml-convert-command
"latexmlmath \"%i\" --presentationmathml=%o"
;; org-latex-listings 'minted
org-latex-listings nil
org-latex-pdf-process
 (list "latexmk -pdf -pdflatex='%latex -interaction=nonstopmode 
-shell-escape' -bibtex -f %f"))
#+end_src

#+RESULTS:
| latexmk -pdf -pdflatex='%latex -interaction=nonstopmode -shell-escape' 
-bibtex -f %f |

Dear list,

I have problems with exploiting /programatically/ the structure of an Org table 
:

I want to write function acting on complex tables, where the original 
information is presented along various statistics. My idea is to isolate the 
original information in a range delimited (by convention) by the first and 
second hlines and  by the first and last columns ; the function should accept 
the whole table and retrieve the original data. /The point is that the function 
should accept a variable number of lines in both the "original data" range and 
the summary information./

Let =ttest= such a table with =hlines= :

#+begin_src org :eval yes :exports both :results replace
,#+name: ttest
| ttest | c1 | c2 | rSum |
|---+++--|
| 3 |  3 |  5 |8 |
| 8 |  8 | 12 |   20 |
|---+++--|
|  cSum | 11 | 17 |   28 |
,#+TBLFM: @>$2..@>$>=vsum(@I..@II)::@2..@>>$4=vsum($<<..$>>)
#+end_src

#+RESULTS:
#+name: ttest
| ttest | c1 | c2 | rSum |
|---+++--|
| 3 |  3 |  5 |8 |
| 8 |  8 | 12 |   20 |
|---+++--|
|  cSum | 11 | 17 |   28 |
#+TBLFM: @>$2..@>$>=vsum(@I..@II)::@2..@>>$4=vsum($<<..$>>)

Passing this table as an argument to source code loses the hlines :

#+begin_src  org :eval yes :exports both :results replace
,#+begin_src emacs-lisp :exports results :results drawer :var foo=ttest
  foo
,#+end_src
#+end_src

The structure allowing to retrieve the original data is lost.

The point is that the source code can't exploit the hlines to find relevant 
information (in the present case, the lines between the hlines).

Alternatively, one may try and pass the relevant range, using 
=foo=(org-table-get-remote-range "ttest" "@I$<<..@II$>>")= as an argument. This 
fails for a different reason :

#+begin_src org :eval yes :exports both :results replace
,#+begin_src emacs-lisp :exports results :results drawer :var 
foo=(org-table-get-remote-range "ttest" "@I$<<..@II$>>")
  foo
,#+end_src
#+end_src

Again, the structure is lost : this time, =foo= is a "flattened" vector, whose 
matricial shape is lost to the processing function.

I am looking for explanations and/or hints.

# Local Variables:
# org-latex_listings: nil
# End: