# Row descriptor -X leads outside table

Emacs Asked on December 26, 2020

I’m trying to calculate a new column on an org table, I’m using the following table formula:

#+TBLFM: $9=if (@# > 15, ([email protected]$6)*100000/10724599, 0)

It’s taking the difference on column 6 between the current row and 14 rows previous.

To prevent it from overrunning the start of the table the current row @# is checked to see there are 14 previous rows to look back over. If not, a zero if filled in.

However when using this formula I get the message:

Row descriptor -14 leads outside table

But it shouldn’t do that as it should only evaluate the true branch when there are >14 previous rows – at least that’s what I thought?

In case Calc formulas don’t respect short-circuiting with if, I tried a lisp construct too – but get the same result using if or when:

#+TBLFM: $9='(if (> @# 15) (/ (* (-$6 @-14$6) 100000) 10724599) 0);N If I replace the -14 for -1 the logic doesn’t fail – I presume, because of the header. How can I achieve a lookback in a formula like the example above? Note – if I comment out the condition that it testing for out of bounds indexes in org-table.el it works fine – which suggests org-table--row-type is being called eagerly on all parameters of if even if they are not used? So perhaps I need to write my own lazy version of if or similar?  (cond ;;((or (< i 0) (>= i l)) ;;(user-error "Row descriptor %s leads outside table" desc)) ;; The last hline doesn't exist. Instead, point to last row ;; in table. ((= i (1- l)) (1- i)) (t i))  If I then turn on debugging formula I can see what is happening for the first row – it does look to me like expansion of the out of bound array happens even though I never use it? With out commenting out the code the debugging does nothing – I assume because the user error is hit before the debugger is started. Substitution history of formula Orig: if (@# > 15, ([email protected]$6)*100000/10724599, 0)
$xyz-> if (@# > 15, ([email protected]$6)*100000/10724599, 0)
@r$c-> if (2 > 15, ($6-(Cumulative_cases))*100000/10724599, 0)
$1-> if (2 > 15, ((1)-(Cumulative_cases))*100000/10724599, 0) Result: 0 Format: NONE Final: 0  Update – it’s not necessary to understand the problem but for reference the full code can be found here: https://github.com/falloutphil/Misc/blob/master/covid.el ## One Answer You may well be right about the eager evaluation (which might be a bug). EDIT: Actually, there is no evaluation at all: the user error is precipitated just by pattern matching - while in row 2, it finds the @-14$6 in the formula and proceeds to check it immediately; it does not matter at all that the formula would never hit that. Fixing that is probably difficult (to say the least).

The only thing I can suggest as a workaround is to fill the first 14 rows of column 9 with zeros, and apply the formula unconditionally to the rest of the rows, using range formulas:

#+TBLFM: #+TBLFM: @[email protected]$9 = 0 :: @[email protected]>$9=([email protected]\$6)*100000/1072459


Correct answer by NickD on December 26, 2020

## Related Questions

### use-package: autoload function outside the main package file

1  Asked on November 15, 2021

### Force Emacs to start in text mode

1  Asked on November 15, 2021 by ddc

### Auto-indentation for Meteor/spacebars

1  Asked on November 13, 2021

### How can I get the tag value associated with a current custom variable?

1  Asked on November 13, 2021 by gct

### How to disable keybinding (C-o) in ido-find-file?

2  Asked on November 13, 2021

### Move point inside of image overlay

2  Asked on November 10, 2021 by cardano

### Required color-theme file missing in Emacs 26

1  Asked on November 10, 2021

### Emacs 26.3: Weird frame title issue with KDE

1  Asked on November 10, 2021 by ed-sabol

### Ignore meta key when inputting unicode on OSX

0  Asked on November 10, 2021

### Recurrent pop-up when queued email sends without internet connection

1  Asked on November 7, 2021

### compilation sentinel: symbol’s value as variable is void for quote, >, <, =, etc

1  Asked on November 5, 2021

### Keybindings with Shift key does not work when CAPS is on

1  Asked on September 2, 2021 by tian

### How to find a file recursively on Microsoft Windows with findutils (gnu find) installed?

1  Asked on September 2, 2021 by vasantha-ganesh

### How to call org-sparse-tree from Lisp?

1  Asked on September 2, 2021 by user2567544

### Flycheck – Eslint: ‘config file: missing or incorrect’

1  Asked on September 2, 2021 by ben-krck

### Displaying some characters with all-icon instead of my current font

1  Asked on September 2, 2021 by lhooq

### Emacs fails to open gnuplot files with extension .gp

1  Asked on September 2, 2021 by paul-c

### Spacemacs kept repositioning the cursor when there’s unmatched parenthesis

1  Asked on September 2, 2021 by searene

### Automatically activating python virtual environments with pyvenv

1  Asked on September 2, 2021 by jacob-pavlock

### In a Python code is it possible to give a color to called functions?

1  Asked on September 2, 2021