all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Formulas on table cells containing '$'
       [not found] <CAF_DUeFAqMNG39-nTz1wxBt5qLyQTyQtT-=mW1jiz-B91Q9B9A.ref@mail.gmail.com>
@ 2023-05-15 21:47 ` Jeff Trull
  2023-05-18 18:55   ` Bruno Barbier
  0 siblings, 1 reply; 2+ messages in thread
From: Jeff Trull @ 2023-05-15 21:47 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 1354 bytes --]

While investigating an error executing a table formula I discovered that
cells containing '$' cause column references to be executed even when no
attempt is made to evaluate cell contents as code. Here's a simple example:

#+TITLE: demonstrate strange error in currency column

| 3/1/2023  | Deposit                | $200.00 |
| 3/13/2023 | Interest               | $1.13   |
| 4/1/2023  | Deposit                | $301.22 |
|-----------+------------------------+---------|
|           | Number of Transactions |         |
#+TBLFM: @4$3='(length '(@1$3..@I$3))

Evaluating the table formula produces a 'Invalid field specifier "$200"'
message. In more complicated examples you just see a #ERROR in the cell.
With formula debugging turned on, I can evaluate the expanded expression
with no errors.

This is surprising for a number of reasons:

   1. The formula makes no use of the cell contents
   2. The formula debugger notes an error but actually shows a valid
   expression
   3. Columns with currencies will be fairly common esp in imports from
   financial institutions
   4. This error happens before the formula is evaluated so there is no
   chance to remove the problem character in the formula as I do with the
   commas ',' which are also present

Is this by design? If so, I was unable to find any documentation explaining
it.

Thanks,
Jeff

[-- Attachment #2: Type: text/html, Size: 1628 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Formulas on table cells containing '$'
  2023-05-15 21:47 ` Formulas on table cells containing '$' Jeff Trull
@ 2023-05-18 18:55   ` Bruno Barbier
  0 siblings, 0 replies; 2+ messages in thread
From: Bruno Barbier @ 2023-05-18 18:55 UTC (permalink / raw)
  To: Jeff Trull, emacs-orgmode


Jeff Trull <edaskel@att.net> writes:

> While investigating an error executing a table formula I discovered that
> cells containing '$' cause column references to be executed even when no
> attempt is made to evaluate cell contents as code. Here's a simple example:
>

Confirmed.


org tries first to resolve all references, recursively.


   '(length '(@1$3..@I$3))

   { resolving @1$3..@I$3 into ("$200.00" "$1.13" "$301.22") }
  
=  '(length '("$200.00" "$1.13" "$301.22"))

   { resolving $200 into ...
  
ERROR: '$200' is an invalid reference.



It's probably not by designed, but, it's definitely a limitation of
the current implementation.


As a workaround, you could hide your reference in elisp and resolve it
manually using `org-table-get-range'. That way you can add/remove "$" as
needed.


For example:

     | 3/1/2023  | Deposit                | $200.00 |
     | 3/13/2023 | Interest               | $1.13   |
     | 4/1/2023  | Deposit                | $301.22 |
     |-----------+------------------------+---------|
     |           | Number of Transactions | 3       |
     |           | Total                  | $502.35 |
     #+TBLFM: @4$3='(length (org-table-get-range (concat "@" "1$" "3..@" "I$" "3")))
     #+TBLFM: @5$3='(format "$%.2f" (apply '+ (mapcar (lambda (x) (string-to-number (substring x 1))) (org-table-get-range (concat "@" "1$" "3..@" "I$" "3")))))




Bruno



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-05-18 18:56 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CAF_DUeFAqMNG39-nTz1wxBt5qLyQTyQtT-=mW1jiz-B91Q9B9A.ref@mail.gmail.com>
2023-05-15 21:47 ` Formulas on table cells containing '$' Jeff Trull
2023-05-18 18:55   ` Bruno Barbier

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.