If I observe a convention of saving my file paths as variables with the common prefix "file_", it seems I could create a wrapper function for read_rds() that would name my read files based on whatever text came after "file_" in the file path's name.
I run into trouble when I evaluate the name I want the read file to take.
library(here)
library(readr)
library(stringr)
file_survey <- here("my_survey_2019.rds")
my_read_rds <- function(file){
name <- deparse(substitute(file))
name <- stringr::str_remove(name, "^file_")
eval(name) <- readr::read_rds(file) # Does not work
}
my_read_rds(file_survey) # would ideally create a dataframe named `survey`
survey <- read_rds(file). This makes functions much easier to deal with and to be called from inside other functions.data.tabledoes not follow a functional programming paradigm, yet it's one of the most popular libraries. People should program the way that they want to, if it makes sense to them or if they have a system.