Created
October 18, 2023 21:51
-
-
Save allaway/fb5a53b935802b6c8a91a922234bc125 to your computer and use it in GitHub Desktop.
convert column names in google sheet to camelCase
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is specifically written with schematic manifests in mind.