Appendix B — Every word in the grammar

The whole vocabulary, on one page. If you are deciding whether to learn this, read the list and see how long it takes. That is the argument, and it is shorter than the argument for it.

Nothing here is typed by hand. The engine is asked what words it has when this page is built, so the list cannot describe a word that was removed or miss one that was added.

Kind Count What they do
Verbs 16 Steps in a pipeline. Every one is an imperative English verb
Aggregations 11 Collapse a group to one value
Windows 7 Answer for every row by looking at the other rows
Scalar functions 20 Answer for one row from that row
Grammar words 30 The small words that join the rest together

B.1 The verbs

A pipeline is a table, then then, then one of these, repeated.

`keep` · `pick` · `add` · `summarize` · `sort` · `take` · `take_last` · `join` · `add_rows` · `drop_duplicates` · `rename` · `drop_missing` · `fill_missing` · `add_combinations` · `lengthen` · `widen`

keep and pick are the two that choose: rows and columns. add and summarize are the two that make a column: one per row, and one per group. sort and take order and cut, and take_last cuts from the other end. Everything after those seven is a second table, a missing value, a change of shape, or the housekeeping pair that renames a column and drops repeated rows.

B.2 The aggregations

These go inside summarize, and inside add when it carries a by.

`total` · `average` · `median` · `smallest` · `largest` · `standard_deviation` · `first` · `last` · `unique_count` · `row_count` · `join_rows`

B.3 The windows

These answer once per row by looking along the other rows. Several of them require a sort in front, because they mean nothing until something has said in what order.

`rank` · `row_number` · `running_total` · `previous` · `following` · `rolling` · `latest`

B.4 The scalar functions

One row in, one value out. These go anywhere a value goes.

`first_present` · `join_text` · `lower` · `upper` · `to_number` · `to_text` · `to_date` · `round_below` · `round_above` · `trim` · `replace_text` · `split_text` · `characters` · `between` · `remainder` · `year` · `month` · `day` · `weekday` · `hour`

B.5 The grammar words

Not verbs and not functions. These are the joints: they say how the words on either side of them are related.

`then` · `where` · `as` · `by` · `all_but` · `descending` · `in` · `is` · `not` · `and` · `or` · `yes` · `no` · `missing` · `unmatched` · `starts` · `ends` · `contains` · `name` · `value` · `kind` · `giving` · `when` · `otherwise` · `look_up` · `matching` · `any` · `every` · `with` · `ties`

B.6 Where each word is first used

Each verb and function below links to the page whose running example uses it first, in the book’s own order. The table is worked out from the chapters when the page is built, the same way the lists above come from the engine. A moved example moves its link, and a word no chapter runs cannot ship at all, because a build check refuses the book first.

Word First running example
keep keep Your first pipeline
pick pick Choosing columns
add add Your first pipeline
summarize summarize Your first pipeline
sort sort Your first pipeline
take take Adding a column
take_last take_last Sorting and taking
join join Missing values
add_rows add_rows Adding rows
drop_duplicates drop_duplicates Renaming and repeats
rename rename Renaming and repeats
drop_missing drop_missing Missing values
fill_missing fill_missing The rows that are not there
add_combinations add_combinations The rows that are not there
lengthen lengthen Columns into rows
widen widen Rows into columns
total total Your first pipeline
average average Summarizing by group
median median Summarizing by group
smallest smallest Summarizing by group
largest largest Summarizing by group
standard_deviation standard_deviation Summarizing by group
first first Summarizing by group
last last Summarizing by group
unique_count unique_count Summarizing by group
row_count row_count Your first pipeline
join_rows join_rows Tidying text
rank rank The words that repeat
row_number row_number Adding a column
first_present first_present Missing values
join_text join_text Tidying text
lower lower Tidying text
upper upper Tidying text
to_number to_number Saying what something is
to_text to_text Saying what something is
to_date to_date Dates
round_below round_below Adding a column
round_above round_above Adding a column
trim trim Tidying text
replace_text replace_text Tidying text
split_text split_text Tidying text
characters characters Tidying text
between between Saying what something is
remainder remainder Adding a column
year year Summarizing by group
month month Dates
day day Dates
weekday weekday Dates
hour hour Dates
running_total running_total The total so far
previous previous The total so far
following following The total so far
rolling rolling The total so far
latest latest Missing values

The grammar words are not in the table on purpose. in, is, not and their siblings are also words the host languages use, so a scan would confidently attribute the wrong page. They are everywhere above instead.

B.7 Every word answers for itself

You do not have to come back here. Each word above has a page where you are already sitting, and every one of them carries an example you can paste.

?keep
?add_combinations
help(god.keep)
help(god.add_combinations)

The two show the same example in the two spellings, down to the same table and the same numbers. That is this book’s claim stated one word at a time. They are run rather than written. The R suite executes the example on every help page, and the Python suite executes every one in every docstring. A page that no longer matches the engine fails a build rather than misleading the reader who went looking.

One difference between those pages and these can surprise you. This book tells Python to print a whole number without its decimal point, so that the tabs of an example agree. Nothing has told your own session that, and a total of whole numbers arrives there as 250.0 rather than 250. The Python help pages show 250.0, because that is what you will see.

B.8 That is all of it

There is no second list, no set of helpers, and no dialect that adds a few more on a cluster. A word that is not above is not in the grammar. Asking for one gets a refusal that lists the words it could have been, and names the nearest when the spelling is close.