7.4 Internal state
Let’s say you want to store the user’s favorite letters. Here is your first attempt:
# make some very small starting data within the file
favorite_letters <- letters[1:3]
#' Report my favorite letters
#' @export
mfl <- function() {
favorite_letters
}
#' Change my favorite letters
#' @export
set_mfl <- function(l = letters[24:26]) {
old <- favorite_letters
favorite_letters <<- l # trying to overwrite a variable in the global environment
invisible(old)
}