4

I would like to use source code blocks in org-mode table formulas using something similar to:

#+NAME: square
#+BEGIN_SRC python :var x=0
return x**2
#+END_SRC

| 1 | 1 |
| 2 | 4 |
| 3 | 9 |
#+TBLFM: $2=$square($1)

Is there any way to accomplish this?

4

Source: http://ehneilsen.net/notebook/orgExamples/org-examples.html#sec-8-2

#+NAME: sampformula
#+BEGIN_SRC python :var angle=90 :var r=2 :exports none
from math import radians, cos
result = r*cos(radians(angle))
return result
#+END_SRC

| angle |  r |             x |
|-------+----+---------------|
|    30 | 10 | 8.66025403784 |
|    45 | 10 | 7.07106781187 |
|    60 | 10 |           5.0 |
#+TBLFM: $3='(org-sbe "sampformula" (angle $1) (r $2))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.