While modern IDEs make it easy to look up arguments to functions, if you actually know function syntax, you can read and understand code more quickly (see The Programmer’s Brain by Felienne Hermans for more information). {pkgflash} generates flashcards to make it easier to learn the syntax of a package’s exported functions.
You can install the development version of pkgflash from GitHub with:
# install.packages("devtools")
devtools::install_github("r4ds/pkgflash")
I need to look into existing options for flashcards before I continue. That might result in a change to what this first function returns, but the general idea is ready.
Let’s say I’m trying to really wrap my head around the {rlang} package. One thing that can help me read {rlang}-using code is to learn the functions and their arguments.
library(pkgflash)
rlang_fns <- pkg_fn_info("rlang")
I can see that there are 432 functions exported from {rlang} (at the time that this README was built).
I use the rlang::ns_env()
function in this package. Let’s look at its
argument(s) (and their default values, if any) to begin to internalize
how this function works.
rlang_fns$ns_env
#> $x
#> caller_env()
The sole argument to rlang::ns_env()
is x
, and its default value is
caller_env()
. That’s another function in {rlang}.
rlang_fns$caller_env
#> $n
#> [1] 1
rlang::caller_env()
takes an argument n
, which tells it how many
callers to go back (ie, how far up the stack to go).
I envision the flashcards eventually showing a function name, and asking you to recall (and eventually maybe type in) the names of its arguments. Or perhaps we’ll allow you to “flip” the card again, by recalling the default values of those arguments.
Long-term, I would like to build in concepts such as spaced repetition and interleaving, to allow you to use this package as a learning tool.
Please note that the pkgflash project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.