Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Function for Reading in Nasty Excel Files #59

Open
wfulp opened this issue Sep 2, 2020 · 0 comments
Open

Function for Reading in Nasty Excel Files #59

wfulp opened this issue Sep 2, 2020 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@wfulp
Copy link
Contributor

wfulp commented Sep 2, 2020

A function to deal with merged cells and multiple header layer levels. Here is a snippet from a super nasty excel:

library(tidyverse)
library(readxl)
library(janitor)

file_path <- 'N:/cavd/Objective 4/GH-VAP/ID43-Barouch/Data/Moderna_mRNA1273_Paper/nejmoa2024671_appendix_2.xlsx'
tmp_names <- read_excel(file_path,
                        sheet = 'Table S2',
                        range = "C5:CL7",
                        col_names = FALSE)
final_names <- tmp_names %>% 
  t() %>% 
  as_tibble() %>% 
  fill(V1, V2) %>% 
  unite(
    col = "colnames",
    V1, V2, V3,
    sep = "_",
    na.rm = TRUE
  ) %>% 
  mutate(final_names = colnames  %>% 
           str_replace_all("(\\r)|(\\n)"," ") %>% 
           str_replace_all("\\s+"," "))
moderna_data_org <- read_excel(file_path,
                               sheet = 'Table S2',
                               skip = 7,
                               col_names = c("Group",final_names$final_names)) %>% 
  clean_names() %>% 
  fill("group")
@wfulp wfulp added the enhancement New feature or request label Sep 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants