Standardize column names of a data frame or line list
Source:R/column_name_standardization.R
      standardize_column_names.RdAll columns names will be reformatted to  snake_case. When the
conversion to snakecase does not work as expected, use the keep and/or
rename arguments to reformat the column name properly.
Arguments
- data
 The input
<data.frame>or<linelist>.- keep
 A
<vector>of column names to maintain as they are. When dealing with a<linelist>, this can be set tolinelist_tags, to maintain the tagged column names. The Default isNULL.- rename
 A named
<vector>of column names to be renamed. This should be in the form ofc(new_name1 = "old_name1", new_name2 = "old_name2")for example.
Examples
# do not rename 'date.of.admission'
cleaned_data <- standardize_column_names(
  data = readRDS(
    system.file("extdata", "test_df.RDS", package = "cleanepi")
  ),
  keep = "date.of.admission"
)
# do not rename 'date.of.admission', but rename 'dateOfBirth' and 'sex' to
# 'DOB' and 'gender' respectively
cleaned_data <- standardize_column_names(
  data = readRDS(
    system.file("extdata", "test_df.RDS", package = "cleanepi")
  ),
  keep = "date.of.admission",
  rename = c(DOB = "dateOfBirth", gender = "sex")
)
# print the report
print_report(
  data = cleaned_data,
  what = "colnames"
)
#>                         before                        after
#> 1                     study_id                     study_id
#> 2                   event_name                   event_name
#> 3                 country_code                 country_code
#> 4                 country_name                 country_name
#> 5            date.of.admission            date.of.admission
#> 6                  dateOfBirth                          DOB
#> 7 date_first_pcr_positive_test date_first_pcr_positive_test
#> 8                          sex                       gender