snake_case | R Documentation |
This function attempts to convert variables to snake_case, even if it's already in snake_case. The important regex lines were posted by Stack Overflow user epost in "Elegant Python function to convert CamelCase to snake_case?".
snake_case(x)
x |
A vector of names to convert. |
A vector of converted names.
This series of regexes has an advantages over the current
implementations of lettercase::str_snake_case()
and snakecase::to_snake_case()
.
The former converts "PatientDOB" to "patientdob" and the latter converts
"patient.dob" to "patient_._dob". I'll keep an eye on these packages
(i.e., lettercase #1 for 'camelCase'
and snakecase #101). I'd prefer
to use one of them, instead of maintaining the functions.
Will Beasley
snake_case(colnames(datasets::OrchardSprays))
snake_case(colnames(datasets::iris))
snake_case(c("PatientID", "PatientDOB", "DOB", "name.last", "name.first"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.