{
library(tidyr)
library(stats)
#### Example 1 --------------------------------------------------------------
# make_name_list generates names that are informative through a line of code
# or function. tibble(iris), iris %>% tibble and
# list(iris = tibble(mytibble) %>% select(Species)) will have 'iris' as name.
list(tibble(iris), tibble(mtcars)) %>%
setNames(make_name_list(list(tibble(iris), tibble(mtcars)), args_list =
c("IRIS %>% complicated_code","complicated_function(MTCARS)")))
#### Example 2 --------------------------------------------------------------
# make_name_list can be used when a function uses arguments provided by the
# user to generate a list. The name is simplified and given to the list
# itself
library(dplyr)
my_function <- function(df){
.fargs <- as.list(match.call(expand.dots = TRUE))
list_df <-
list(df) %>%
setNames(.,make_name_list(as.character(.fargs['df']),list(df)))
return(list_df)}
my_function(tibble(iris))
my_function(iris %>% tibble %>% select(Species))
}
Run the code above in your browser using DataLab