design
design copied to clipboard
Pattern: serve internal data in a humane way
Placeholder for another concrete pattern that recurs in tidyverse/r-lib packages, like #53 Pattern: Cross that Bridge When you Come To It
Sometimes internal data is also useful to users. Write a helper to give it to them in usable way.
Examples:
readr::readr_example(),readxl::readxl_example()for accessing example files that ship with the packagesgoogledrive::drive_endpoints(),googledrive::drive_mime_type()for accessing pre-processed knowledge about the Drive API
NULL input means "show me everything"
character or integer input is for selective access
I'm not sure if I like the NULL input = "show me everything" — doesn't that violate type stability?
It depends on what sort of type stability you mean. All of these functions always return something of fixed type (an atomic vector or a list). But yes it is true that the NULL input has length zero and the return value does not.
In googledrive, I created an expose() sentinel for this, inspired by ggplot2::waiver(), but I think you eventually indicated you didn't like that either.
Do you have other ideas for conveying "show me the whole object"?
Maybe a plural? e.g. readr::readr_example(name) vs readr::readr_examples()?
I like use the plural, it also aids discoverability and you can document them together.
I will do that in vroom.