Skip to contents

Montana has eleven native broadleaf (hardwood) trees, from the box elders and green ash of the eastern river bottoms to the aspen groves and paper birches of the mountains. This vignette shows a dichotomous key to them, written as a plain spreadsheet with a folder of photos, and the two ways dimoose can show it: a printable diagram and an interactive wizard.

Make your own key in three steps

The key is an ordinary CSV file, so the quickest way to write a key of your own is to start from a copy of it:

  1. Copy the template. It ships with dimoose, next to its photos:

    template <- system.file("extdata", "montana", package = "dimoose")
    dir.create("~/my-key")
    file.copy(template, "~/my-key", recursive = TRUE)   # makes ~/my-key/montana/
  2. Edit it in Excel, Numbers or Google Sheets. One row per lead:

    Column What goes in it
    Couplet The couplet’s number.
    Choice Optional: a, b, …; left blank, the leads are lettered in order.
    Question Optional: what the couplet asks, such as “Leaf type?”.
    Description What the lead says.
    Goes to The next couplet, or blank when the lead names a species.
    Species The result, written “Common name (Genus species)”.
    Photo Optional: photo file names in the same folder, separated by ;.

    Put your photos in the same folder and save the sheet as CSV.

  3. Build the key and look at it:

    library(dimoose)
    k <- keyFromSpreadsheet("~/my-key/montana/montana-key.csv", desc = "My key")
    k$validate()                       # lists any couplet that is never reached, etc.
    keyDiagram(k, "my-key.svg")        # a printable diagram
    exportWizard(k, "my-key.html")     # an interactive key for phones and browsers

If a row points to a couplet that is not in the sheet, or names a photo that is not in the folder, keyFromSpreadsheet() says which spreadsheet row to fix.

The Montana key

library(dimoose)
k <- montanaKey()
k
#> <dimoose key> Key to the native broadleaf trees of Montana
#>   10 couplets, 20 leads, 11 taxa, up to 7 steps deep

montanaKey() is keyFromSpreadsheet() applied to the template above. Its first rows:

csv <- system.file("extdata", "montana", "montana-key.csv", package = "dimoose")
head(read.csv(csv, check.names = FALSE), 4)
#>   Couplet Choice   Question
#> 1       1      a Leaf type?
#> 2       1      b Leaf type?
#> 3       2      a  Leaflets?
#> 4       2      b  Leaflets?
#>                                                                                  Description
#> 1                                           Leaves compound, divided into separate leaflets.
#> 2                                                             Leaves simple, a single blade.
#> 3 Leaves opposite, with 3 (rarely 5) leaflets that have a few coarse teeth or shallow lobes.
#> 4                                Leaves opposite, with 5 to 7 leaflets with toothed margins.
#>   Goes to                            Species                           Photo
#> 1       2                                    fraxinus_pennsylvanica_leaf.jpg
#> 2       3                                         populus_deltoides_leaf.jpg
#> 3      NA           Box elder (Acer negundo)           acer_negundo_leaf.jpg
#> 4      NA Green ash (Fraxinus pennsylvanica) fraxinus_pennsylvanica_leaf.jpg

Every species was checked as native to Montana in the Montana Field Guide and USDA PLANTS. Common hackberry is left out because the Montana Field Guide gives its origin in the state as undetermined, and American elm because it is planted rather than native. The characters in each couplet come from the Montana Field Guide’s descriptions and, for leaf stalks and buds, the Virginia Tech Dendrology fact sheets; ?montana lists the sources. The 14 photos are from Wikimedia Commons, most of them taken in Montana by Matt Lavin; their authors and licenses are in the package’s COPYRIGHTS file.

A diagram of the key

keyDiagram() draws any key top-down: each question in a blue box, its leads below it, and each species in a green box with its photo.

keyDiagram(k, "montana-key.svg")
Key to the native broadleaf trees of Montana Key to the native broadleaf trees of Montana1. Leaf type?1a. Leaves compound,divided into separateleaflets.2. Leaflets?2a. Leaves opposite, with3 (rarely 5) leafletsthat have a few coarseteeth or shallow lobes.Box elderAcer negundo2b. Leaves opposite, with5 to 7 leaflets withtoothed margins.Green ashFraxinus pennsylvanica1b. Leaves simple, asingle blade.3. Leaf arrangement?3a. Leaves opposite, with3 to 5 toothed lobes andred leaf stalks.Rocky Mountain mapleAcer glabrum3b. Leaves alternate.4. Leaf lobes?4a. Leaves deeply lobed,the lobes rounded; fruitan acorn.Bur oakQuercus macrocarpa4b. Leaves not lobed.5. Leaf shape?5a. Leaves narrowlylance-shaped, at least2.5 times as long aswide.6. Buds?6a. Buds small andpressed against the twig,each covered by a singlecap-like scale; leaves 3to 8 cm long, whitishbeneath.Peachleaf willowSalix amygdaloides6b. Buds long (about 2.5cm), curved, resinous andfragrant; leaves 4 to 11cm long.Narrowleaf cottonwoodPopulus angustifolia5b. Leaves broader:rounded, triangular orbroadly lance-shaped.7. Leaf stalk?7a. Leaf stalks flattenedfrom side to side.8. Leaf shape and teeth?8a. Leaves nearly round,2 to 8 cm long, finelytoothed; bark smooth andpale.Quaking aspenPopulus tremuloides8b. Leaves triangular,about as long as wide,with teeth at least 1 mmdeep.Plains cottonwoodPopulus deltoides7b. Leaf stalks round, oronly slightly flattened.9. Leaf size?9a. Leaves 5 to 15 cmlong, silvery whitebeneath with rusty smearsof resin.Black cottonwoodPopulus trichocarpa9b. Leaves 2 to 7 cmlong, with sharp teeth,not silvery whitebeneath.10. Bark?10a. Bark white andpeeling on older trees.Paper birchBetula papyrifera10b. Bark gray to brown,only slightly peeling; asmall tree or large shrubalong streams.Water birchBetula occidentalis

An interactive key

exportWizard() writes the same key as a single web page that asks one question at a time and shows the photos with each answer. It works offline, so it can be copied to a phone and used in the field.

page <- tempfile(fileext = ".html")
exportWizard(k, page)

Open the file in a browser to try it.

Diagrams of other keys

keyDiagram() works on every dimoose key, whichever way it was made. Here is the key to the orders of Arachnida, transcribed from a textbook:

keyDiagram(arachnidaKey(), "arachnida.svg")