Skip to content

Instantly share code, notes, and snippets.

@allaway
Created October 18, 2023 21:51
Show Gist options
  • Save allaway/fb5a53b935802b6c8a91a922234bc125 to your computer and use it in GitHub Desktop.
Save allaway/fb5a53b935802b6c8a91a922234bc125 to your computer and use it in GitHub Desktop.
convert column names in google sheet to camelCase
library(googlesheets4)
gs4_auth()
convert_colname_to_camelcase <- function(ss_url) {
# Read the sheet
ss_data <- range_read(ss_url, n_max = 0)
colnames(ss_data)[colnames(ss_data)!="Component"] <- sapply(colnames(ss_data)[colnames(ss_data)!="Component"], stringr::str_replace, "_", "")
# Convert column names to camelCase
colnames(ss_data)[colnames(ss_data)!="Component"] <- sapply(colnames(ss_data)[colnames(ss_data)!="Component"], R.utils::toCamelCase)
# Update the Google Sheet with the new column names
range_write(ss_url, ss_data, range = "A1", col_names = TRUE, reformat = FALSE)
}
foo <- googledrive::drive_ls("https://drive.google.com/drive/u/1/folders/1NJcXcGEDWmlTsRtyLtuwgH_5pbX0Dd9C")
sapply(foo$id, convert_colname_to_camelcase)
@allaway
Copy link
Author

allaway commented Oct 18, 2023

This is specifically written with schematic manifests in mind.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment