5 Function names
Follow the style guide (i.e. use
5.1 Nouns vs verbs
In general, prefer verbs. Use imperative mood:
Exception: noun-y interfaces where you’re building up a complex object like ggplot2 or recipes (verb-y interface in ggvis was a mistake).
Nouns should be singular (
geom_points()), simply because the plurisation rules in English are complex.
5.2 Function families
Use prefixes to group functions together based on common input or common purpose. Prefixes are better than suffixes because of auto-complete. Examples: ggplot2, purrr. Counter example: shiny.
Not sure about common prefixes for a package. Works well for stringr (esp. with stringi), forcats, xml2, and rvest. But there’s only a limited number of short prefixes and I think it would break down if every package did it.
Use suffixes for variations on a theme (e.g.
Strive for thematic unity in related functions. Can you make related fuctions rhyme? Or have the same number of letters? Or similar background (i.e. all Germanic origins vs. French).
Err on the side of too long rather than too short (reading is generally more important than writing). Autocomplete will mostly take care of the nuisance and you can always shorten later if you come up with a better name. (But hard to make long later, and you may take up a good word that is a lot of work to reclaim later).
Length of name should be inversely proportional to frequency of usage. Reserve very short words for functions that are likely to be used very frequently.
You can’t expect to avoid conflicts with every existing CRAN package, but you should strive to avoid conflicts with “nearby” packages (i.e. packages that are commonly used with your package).
- List of common verbs
- Rhyming dictionary