emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Orgmode] graphing from org-tables


From: Carsten Dominik
Subject: Re: [Orgmode] graphing from org-tables
Date: Fri, 23 Jan 2009 08:30:31 +0100


On Jan 23, 2009, at 2:37 AM, Eric Schulte wrote:

Dan Davison <address@hidden> writes:

On Mon, Dec 22, 2008 at 12:00:14PM -0500, Eric Schulte wrote:
Hi Dan,


<...>

2) Also interesting is the idea of referencing a table from a block of R
  code elsewhere in the org file.  I've worked some on processing
  blocks of R code in org files in a manner similar to Sweave.
  http://github.com/eschulte/org-contrib/tree/master/org-exp-blocks.el
  If we could implement a simple means of referencing tables (either
whole tables, or cells/cols/rows of tables) from these R-code blocks
  then that seems like it may be fairly powerful.

I agree with this. So in the case of my code, I think we would like to
be able to do something like

#+TBLR: data:<org-table-reference> columns:(1 2) action:tabulate

This would make the output of the analysis/plot of the table pointed
to by <org-table-reference> appear at the location in the file of the
#+TBLR line. Perhaps one design aim would be to have the same
mechanism work for referencing tables for processing by #TBLFM,
org-plot, org-table-R, org-exp-blocks, etc.

That sounds like a very good idea. A uniform interface for referencing table ranges (either globally from outside of the table or locally from
within the table) that could be used for any table formula be it in
calc, R, elisp, etc... I find the idea of easily accessing and writing
table data from external tools very intriguing

For what it is worth,  here is a function that will grab a field value
or a range from a remote table, be it in the current file or in a
different file.  That is not yet a syntax to have such a reference
in a formula, but it is the most important component, and maybe it will
already be useful for you.

This function uses an entry ID to access the table - obviously
other schemes like table naming could be used.

It is not going to be very fast, and multiple accesses
to the same remote table would each cause the same overhead,
but it sure is working.

- Carsten

(defun org-table-remote-range (id form
                                  &optional replace keep-empty numbers lispp)
  "Get a field value or a list of values in a range from table at ID.

ID refers to an entry, and the first table in that entry is the one
being looked at.
FORM is a field or range descriptor like \"@2$3\" or \"@address@hidden".
All the references must be absolute, not relative.
When REPLACE is non-nil, the return value will be a string in which the field descriptor has been replaced, according to the flags KEEP-EMPTY, NUMBERS, and LISPP. These flags correspond to the E and N flags, and to the fact if the
formula is a lisp formula, not a calc formula.

When REPLACE is nil, a single string or a list of strings is returned,
with with the content(s) of the referenced field(s)."
  (save-match-data
    (let ((id-loc (org-id-find id 'marker))
          org-table-column-names org-table-column-name-regexp
          org-table-local-parameters org-table-named-field-locations
          org-table-current-line-types org-table-current-begin-line
          org-table-current-begin-pos org-table-dlines
          org-table-hlines org-table-last-alignment
          org-table-last-column-widths org-table-last-alignment
          org-table-last-column-widths tbeg rtn)
      (save-excursion
        (switch-to-buffer (marker-buffer id-loc))
        (save-excursion
          (save-restriction
            (widen)
            (goto-char id-loc)
            (forward-char 1)
            (unless (and (re-search-forward "^\\(\\*+ \\)\\|[ \t]*|" nil t)
                         (not (match-beginning 1)))
              (error "Cannot find a table at ID %s" id))
            (setq tbeg (point-at-bol))
            (org-table-get-specials)
            (when (and (string-match org-table-range-regexp form)
                       (> (length (match-string 0 form)) 1))
              (save-match-data
                (setq rtn (org-table-get-range
                           (match-string 0 form) tbeg 1))))
            (if replace
                (replace-match
                 (save-match-data
                   (org-table-make-reference rtn keep-empty numbers lispp))
                 t t form)
              rtn)))))))






reply via email to

[Prev in Thread] Current Thread [Next in Thread]