Skip to content

Instantly share code, notes, and snippets.

@mhoban
Last active December 30, 2020 17:44
Show Gist options
  • Save mhoban/2bd9f6293658e9c563d54abd65f12bdf to your computer and use it in GitHub Desktop.
Save mhoban/2bd9f6293658e9c563d54abd65f12bdf to your computer and use it in GitHub Desktop.
library(tidyverse)
library(readxl)
library(writexl)
# which file to mess with
xlfile <- "~/tmp/bookofthedead.xlsx"
sheets <- excel_sheets(xlfile)
xlsheets <- map(sheets,~{
read_xlsx(xlfile,sheet=.x)
}) %>% set_names(sheets)
# which sheet to mess with
which_sheet <- "first sheet"
# add the new column
xlsheets[[which_sheet]] <- xlsheets[[which_sheet]] %>%
mutate(newcolumn = paste0("a new value plus ",seq(nrow(.))))
# write the new file
write_xlsx(xlsheets,"~/tmp/bookofthedead2.xlsx",format_headers = FALSE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment