Usecase:
when exporting excel sheets with different datasets you would naturally pass them through a list so that you modulise your code and not to do reptitive work. To get tab names you need to convert those object names into a vector of strings. Imaging when you have so many of them
# so you know the datasets here
list_data <- list(
mtcars,
cars,
Seatbelts,
UKDriverDeaths
)
# the output should be
c(
"mtcars",
"cars",
"Seatbelts",
"UKDriverDeaths"
)
# tested this and it worked but I cannot modulise it for some reason
library(tidyverse)
# prepare data ----
list_data <- list(
mtcars,
cars,
Seatbelts,
UKDriverDeaths
)
# this gets a good output but not sure why I cannot convert it into a function
list_sheets <- list(mtcars,
cars,
Seatbelts,
UKDriverDeaths) |>
quote() |>
# print() |>
as.character() |>
tibble(list_sheets=_) |>
slice(-1) |>
pull()
# trying to do a function
parse_sheet_names <- function(x){
x |>
quote() |>
print() |>
as.character() |>
tibble(list_sheets=_) |>
slice(-1) |>
pull()
}
# testing the function
list(mtcars,
cars,
Seatbelts,
UKDriverDeaths) |>
parse_sheet_names()
list_data |>
map(~parse_sheet_names)