| |
- Designates a table
|-
- Followed by a space will create a horizontal line
- you can navigate them intuitively with tab return etc
Name Age Gavin 100 $solve\left( [x = y + 10, y=10], [x,y] \right)$
- My arrow keys are broken at the moment but additional shortcuts
exist to navigate and rearange using them e.g.
- Move a field
- S-Left S-right
- Move a column
- M-Left M-Right
- Move a row
- M-Down M-Up
- Deleting a row
- S-M-Up
- Adding a row
- , S-M-Down
- Deleting a column
- S-M-Down
- Adding a column
- , S-M-up
tim 20 jane 10 jim 30 30 20 10
Don’t worry about the arrow keys too much. Learn them when you find yourself repeating things
- Copy pasting
- C-c C-x M-w(copy)/C-w(cut)/C-y(paste) lets
ex | val | age |
---|---|---|
james | 12 | 40 |
tim | 2 | 30 |
ex3 | val | |
james | ||
tim |
- C-c |
- converts CSV or TSV into a table
- useful when copy and pasting from websites
e.g.
cats,dogs,birds
- M-x org-table-import
- import a csv or tsv as a table
- ~/results/results.csv
- C-c =
- set a calculation for a column
- C-u C-c =
- set a calculation for a specific field
How I usually add a formula to a table is simply using := in a field and hitting tab
10 | 20 |
1 | 11 |
12 | 0 |
- NOTE: the TBLFM at the bottom keeps track of these formulas for us.
- C-c *
- to recalculate fields
- C-u C-c C-c
- will also align, and calculate
One of the powerful parts of org tables is the ability to do spreadsheet like references.
- C-c ’
- edit the formula for a specific field
- lets you use S-arrows to reference different fields
test | thing |
1 | 11 |
- C-c }
- Display locations inline
- C-c ?
- Get the location of the current element
- C-c C-c
- will also align
- references
- @ Refers to the row
- $ Refers to the column
- > Means the last of the
- .. is used to create a range
test | face |
---|---|
0 | 10 |
20 | 108 |
[0, 10, 20, 108] |
- Remote tables
Thing | Cost |
---|---|
Car | 50000 |
House | 1000000 |
Total |
---|
1050000 |
- calc#Top
While tables are great as is they sometimes we want more than just a simple hand written table
Ensure you have the proper babel support setup
(org-babel-do-load-languages
'org-babel-load-languages
'((sqlite . t)
(R . t)
(python . t)
(emacs-lisp . t)))
One common usecase for tables you will see is displaying results from org babel
return [i for i in range(5)]
Pretty Cool Hey?
We can also intake this data
From | To |
---|---|
jim | john |
tim | drake |
griff | step |
(reduce #'concat
(mapcar (lambda (row) (format "from %s to %s\n"
(cl-first row) (cl-second row)))
data))
Setup sqlite support for org-babel
What about something more advanced (and useful) like investigating a database
Here I will poke at a sqlite db I have containing multiple resturants
SELECT * FROM resturants LIMIT 10;
Thats a little noisy so lets select some important attributes
SELECT name, rating, hours, category, latitude, longitude FROM resturants LIMIT 10;
Now while exporting those results is useful what about importing them?
Yes some languages let you import tables. Probably the most useful example being sql
lets create a new database for this one
Who | Task |
---|---|
Gavin | “Make Video” |
Gavin | “Edit Video” |
Jim | “Be Cool” |
Tim | “Do Your Thing” |
- NOTE: we are setting the value of the variable
sometable
to be our testtable
DROP TABLE IF EXISTS ntable;
.import $sometable ntable
SELECT Who, Task FROM ntable where Who is 'Gavin';
Lets have a peek at what was just stored in the DB
Open DB
For those interested in learning more
Another usecase is working with mathmatical programming languages like R
- NOTE: R language support comes from the 3rd party ESS package
Make sure that you have R setup to work with org babel after installing ess
Install R support
(use-package ess :ensure t)
Allow for execution of R code
(org-babel-do-load-languages
'org-babel-load-languages
'((R . t)))
Month | Degrees |
---|---|
1 | 3.8 |
2 | 4.1 |
3 | 6.3 |
4 | 9.0 |
5 | 11.9 |
6 | 15.1 |
7 | 17.1 |
8 | 17.4 |
9 | 15.7 |
10 | 11.8 |
11 | 7.7 |
12 | 4.8 |
plot(data, type="b", bty="l", col=c("#ABD249"), las=1, lwd=4)
grid(nx=NULL, ny=NULL, col=c("#E8E8E8"), lwd=1)
legend("bottom", legend=c("Degrees"), col=c("#ABD249"), pch=c(19))
We can preview these results using C-c C-x C-v
If usecases like this interest you but emacs is new to you have a look at