Skip to contents

This function takes messy column names and returns clean ones that work well with R by default. Names that are all lower case with no R-unfriendly characters such as spaces and - are returned.

Usage

format_column_names(column_names)

Arguments

column_names

Column names to be cleaned

Value

Column names cleaned.

Examples

# \donttest{
if(curl::has_internet()) {
crashes_raw = read_collisions(year = 2022)
column_names = names(crashes_raw)
column_names
format_column_names(column_names = column_names)
}
#> Reading in: 
#> /tmp/RtmpNIg6OY/dft-road-casualty-statistics-collision-2022.csv
#> date and time columns present, creating formatted datetime column
#> Warning: NAs introduced by coercion
#> Warning: NAs introduced by coercion
#> Warning: NAs introduced by coercion
#>  [1] "accident_index"                             
#>  [2] "accident_year"                              
#>  [3] "accident_reference"                         
#>  [4] "location_easting_osgr"                      
#>  [5] "location_northing_osgr"                     
#>  [6] "longitude"                                  
#>  [7] "latitude"                                   
#>  [8] "police_force"                               
#>  [9] "accident_severity"                          
#> [10] "number_of_vehicles"                         
#> [11] "number_of_casualties"                       
#> [12] "date"                                       
#> [13] "day_of_week"                                
#> [14] "time"                                       
#> [15] "local_authority_district"                   
#> [16] "local_authority_ons_district"               
#> [17] "local_authority_highway"                    
#> [18] "first_road_class"                           
#> [19] "first_road_number"                          
#> [20] "road_type"                                  
#> [21] "speed_limit"                                
#> [22] "junction_detail"                            
#> [23] "junction_control"                           
#> [24] "second_road_class"                          
#> [25] "second_road_number"                         
#> [26] "pedestrian_crossing_human_control"          
#> [27] "pedestrian_crossing_physical_facilities"    
#> [28] "light_conditions"                           
#> [29] "weather_conditions"                         
#> [30] "road_surface_conditions"                    
#> [31] "special_conditions_at_site"                 
#> [32] "carriageway_hazards"                        
#> [33] "urban_or_rural_area"                        
#> [34] "did_police_officer_attend_scene_of_accident"
#> [35] "trunk_road_flag"                            
#> [36] "lsoa_of_accident_location"                  
#> [37] "enhanced_severity_collision"                
#> [38] "datetime"                                   
# }