emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Emmanuel Charpentier <emm.charpentier@free.fr>
To: emacs-orgmode@gnu.org
Subject: How to retrieve ALL the information of an Org table ?
Date: Sat, 09 Oct 2021 22:36:17 +0200	[thread overview]
Message-ID: <6098f0e50f27c9e15ef6678362bd58a86f1d9c05.camel@free.fr> (raw)


[-- Attachment #1.1: Type: text/plain, Size: 1868 bytes --]

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


[-- Attachment #1.2: Type: text/html, Size: 8811 bytes --]

[-- Attachment #2: TstTableRange.org --]
[-- Type: text/plain, Size: 2782 bytes --]

#+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:

             reply	other threads:[~2021-10-09 20:37 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-09 20:36 Emmanuel Charpentier [this message]
2021-10-10  1:03 ` How to retrieve ALL the information of an Org table ? Ihor Radchenko

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://www.orgmode.org/

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

  git send-email \
    --in-reply-to=6098f0e50f27c9e15ef6678362bd58a86f1d9c05.camel@free.fr \
    --to=emm.charpentier@free.fr \
    --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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).