Suppose I have the following code. This code will take a string containing a file path to a .txt file and read it in as a tibble and then rename the column y
to whatever the filename was. I'm curious if I'm adding too much syntactic sugar and sacrificing easy readability or consistent programming principles. When is it advisable to use as_mapper()
vs creating a function?
# Clean up file name to add to data set
clean_name <- compose(quo_name,
partial(str_remove, pattern = ".txt"),
basename)
# Function to read in the data and make proper adjustments
read_and_rename <- as_mapper(
~ read_csv(.x) %>%
mutate(x = x + 215833) %>%
rename(time = x,
!!clean_name(.x) := y) %>%
gather(key = "test", value = "temp", -time)
)