I'm importing blocks of data from Excel spreadsheets, processing then plotting with ggplot.
I've discovered how to use a 'labeller' but so far have to hand create them. I'd like to have the top row in my spreadsheet have the desired titles and import that, then the data, then use both to create a labeller.
I've got several spreadsheets to process, some which combine data from other sources so I can't just name the columns with what I want in the first place.
# Reads in the top row then the data sc_titles <- read_excel("data/S_Testing_data.xlsx", sheet = "dhb", range = "A1:D1") sc_data<- read_excel("data/S_Testing_data.xlsx", sheet = "dhb", range = "A2:D100") # Extracts the titles and the column names from the data col_names <- names(sc_titles) col_names_data <- names(sc_data) # This is a hand written labeller which does the job but I need to write and maintain one for each spreadsheet # The desired code would generate this from 'col_names' and 'col_names_data' above. sc_labels <- as_labeller(c( `data_1` = "Data Field 1", `data_2` = "Data Field 2", `data_3` = "Data Field 3", `data_4` = "Data Field 4" ))