a <- 5
b <- 7
do_not_want <- 13
# save the elements of our workspace we want
saveRDS(as_named_list(a, b), 'example_data.RDS')
# clear values out of our workspace for the example
rm(list = ls())
# notice workspace environemnt now empty
# read back while documenting what we expect to
# read in
unpack[a, b] <- readRDS('example_data.RDS') # confirm what we have, the extra unpack is a side # effect of the <- notation. To avoid this instead # use one of: # unpack(readRDS('example_data.RDS'), a, b) # readRDS('example_data.RDS') %.>% unpack(., a, b)
# readRDS('example_data.RDS') %.>% unpack[a, b]
#>  "a" "b" "unpack"
# notice do_not_want is not present
#>  5
#>  7
We have new documentation on the new as_named_list helper function here.
The idea is: this is a case where non-standard evaluation is working for us (and clarity/safety) as it forces the user to document each object they want written out (by explicitly naming them), and exactly what objects they expect to come back (again by explicitly naming them right at the assignment location).