Make your package spherical
This article is originally published at http://www.markvanderloo.eu
Larger packages typically consist of functions that are visible to the users (exported functions) and functions that are used by the exported functions, but that are invisible to the user. For example:
# exported, user-visible function
inch2cm <- function(x){
x*conversion_factor("inch")
}
# not exported function, package-internal
conversion_factor <- function(unit){
confac <- c(inch=2.54, pound=1/2.2056)
confac[unit]
}
We can think of the exported functions (or more correctly, the interface of the exported functins) as the surface of a package, and all the other functions as the volume. The surface is what a user sees, the volume is what the developer sees. The surface is how a user interacts with a package.
If the surface is small (few functions exported, no unnecessary parameters in the interface), users are limited in the ways they can interact with your package, and that means there is less to test. It also means that you, as a package developer, have more room to move and change things in the volume. So as a rule of thumb, it is a good idea to keep the surface small.
Since a sphere has the smallest surface-to-volume ratio possible, I refer to this rule of thumb as as make your package spherical.
Note
This post was first published as a paragraph in the vignette of the tinytest package. I repeat it here with a few changes for more visibility.
Thanks for visiting r-craft.org
This article is originally published at http://www.markvanderloo.eu
Please visit source website for post related comments.