tidyImportedDataUnderscore <- function(data) { # note: I tested this against my original script and it gives identical results # pair == TRUE means that the headers of the columns have some information about what pair the larvae were from # if there is no pair data, set pair = FALSE so we don't screw up the columns when we split rawdata2 <- t(data) rawNames <- rownames(rawdata2) rawNames[1] <- "FishName" rownames(rawdata2) <- rawNames rawdata4 <- as.data.frame(rawdata2) rawdata4 <- rownames_to_column(rawdata4) columnHeaders <- rawdata4[1,] colnames(rawdata4) <- columnHeaders rawdata4 <- rawdata4[-1,] #gets rid of header row rawdata4 <- as_tibble(rawdata4) splitCols <- rawdata4 %>% separate("FishName", into = c("fishNum","allElse"), sep = "_") %>% separate("allElse", into = c("pair", "geno", "pheno", "collected", "imaged"), sep = "\\.") %>% unite("uniqueID", fishNum:imaged, remove = FALSE) %>% mutate(imaged = as.character(imaged)) %>% mutate(collected = as.character(collected)) %>% clean_names() return(splitCols) }