Skip to content

Commit e9cd246

Browse files
committed
Formatting style changes using AIR
1 parent f899e98 commit e9cd246

7 files changed

Lines changed: 252 additions & 97 deletions

File tree

R/create_dashboard.R

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,20 @@ create_dashboard <- function(path) {
4646
if (dir.exists(path)) {
4747
# Display a menu asking to confirm folder's overwrite
4848
cli::cli_alert_danger("The folder {path} already exists.")
49-
choice <- menu(c("Overwrite", "Cancel"), title = "What would you like to do?")
50-
49+
choice <- menu(
50+
c("Overwrite", "Cancel"),
51+
title = "What would you like to do?"
52+
)
53+
5154
# Handle the user's choice
52-
if (choice == 2 || choice == 0) { # 2 = Cancel, 0 = No selection
53-
cli::cli_alert_info("Operation cancelled. No files were copied to avoid overwriting folder.")
55+
if (choice == 2 || choice == 0) {
56+
# 2 = Cancel, 0 = No selection
57+
cli::cli_alert_info(
58+
"Operation cancelled. No files were copied to avoid overwriting folder."
59+
)
5460
return(invisible(NULL)) # Exit the function without further execution
5561
}
56-
62+
5763
# If the user selects "Overwrite", proceed
5864
cli::cli_alert_info("Overwritting the folder {path}/ ...")
5965
}
@@ -91,5 +97,7 @@ create_dashboard <- function(path) {
9197

9298
absolute_path <- paste0(getwd(), "/", path)
9399

94-
cli::cli_alert_success("Dashboard scaffolded successfully at: {absolute_path}.")
100+
cli::cli_alert_success(
101+
"Dashboard scaffolded successfully at: {absolute_path}."
102+
)
95103
}

R/diaries_contributions.R

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
get_contributions_diaries <- function(users) {
1212
# Load required package
1313
if (!requireNamespace("tidyRSS", quietly = TRUE)) {
14-
stop("The 'tidyRSS' package is required but not installed. Please install it first.")
14+
stop(
15+
"The 'tidyRSS' package is required but not installed. Please install it first."
16+
)
1517
}
1618

1719
# Initialize an empty list to store dataframes
@@ -21,16 +23,18 @@ get_contributions_diaries <- function(users) {
2123
for (user in users) {
2224
url <- paste0("https://www.openstreetmap.org/user/", user, "/diary/rss")
2325
# Parse the RSS feed and handle potential errors
24-
tryCatch({
25-
feed_data <- tidyRSS::tidyfeed(url, list = FALSE) |>
26-
dplyr::select(-item_category) |>
27-
dplyr::mutate(user = user, .before = 1)
26+
tryCatch(
27+
{
28+
feed_data <- tidyRSS::tidyfeed(url, list = FALSE) |>
29+
dplyr::select(-item_category) |>
30+
dplyr::mutate(user = user, .before = 1)
2831

29-
all_data[[url]] <- feed_data
30-
31-
}, error = function(e) {
32-
warning(paste("Failed to parse URL:", url, "Error:", e$message))
33-
})
32+
all_data[[url]] <- feed_data
33+
},
34+
error = function(e) {
35+
warning(paste("Failed to parse URL:", url, "Error:", e$message))
36+
}
37+
)
3438
}
3539

3640
# Combine all dataframes into one

R/key_classifications.R

Lines changed: 155 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#' Categorises OSM's keys
22
#'
33
#' @description
4-
#' Generates a hierarchical categorisation of OSM keys, based on the type of information they convey.
4+
#' Generates a hierarchical categorisation of OSM keys, based on the type of information they convey.
55
#' For a given dataframe, this function generates two extra columns called `top_key` and `parent_key` whose values will depend on the values from the this function.
6-
#'
6+
#'
77
#' @param df a dataframe with keys and values generated by [extract_and_combine_tags()]
88
#'
99
#' @returns a new dataframe with the same columns and two extra ones called `top_key` and `parent_key` with values defined by this function.
@@ -14,103 +14,217 @@
1414
#' key = c("wheelchair", "building:levels", "highway")
1515
#' )
1616
#' categorise_keys(df)
17-
#'
17+
#'
1818
categorise_keys <- function(df) {
1919
accessibility_keys <- c(
20-
"wheelchair", "ramp", "tactile_paving", "traffic_signals:sound",
21-
"traffic_signals:vibration", "bench",
20+
"wheelchair",
21+
"ramp",
22+
"tactile_paving",
23+
"traffic_signals:sound",
24+
"traffic_signals:vibration",
25+
"bench",
2226
"handrail"
2327
)
24-
amenity_keys <- c("cuisine", "opening_hours", "office", "phone", "website", "takeaway", "school")
28+
amenity_keys <- c(
29+
"cuisine",
30+
"opening_hours",
31+
"office",
32+
"phone",
33+
"website",
34+
"takeaway",
35+
"school"
36+
)
2537

26-
boundaries_keys <- c("admin_level", "boundary", "claimed_by", "disputed", "place", "landuse")
38+
boundaries_keys <- c(
39+
"admin_level",
40+
"boundary",
41+
"claimed_by",
42+
"disputed",
43+
"place",
44+
"landuse"
45+
)
2746

28-
care_keys <- c("emergency", "clinic", "emergency", "health", "hospital", "medical", "shelter", "social_facility")
47+
care_keys <- c(
48+
"emergency",
49+
"clinic",
50+
"emergency",
51+
"health",
52+
"hospital",
53+
"medical",
54+
"shelter",
55+
"social_facility"
56+
)
57+
58+
contact_keys <- c(
59+
"contact",
60+
"email",
61+
"fax",
62+
"opening_hours",
63+
"phone",
64+
"website"
65+
)
2966

30-
contact_keys <- c("contact", "email", "fax", "opening_hours", "phone", "website")
31-
3267
edi_keys <- c("lgbtq", "women", "refugee", "wheelchair")
33-
68+
3469
health_keys <- c("hospital")
3570

3671
highway_keys <- c(
37-
"access", "barrier", "bench", "bin", "bridge", "handrail", "highway", "incline", "lanes", "lit", "oneway",
38-
"ramp", "sac_scale", "segregated", "service", "smoothness", "tracktype", "width"
72+
"access",
73+
"barrier",
74+
"bench",
75+
"bin",
76+
"bridge",
77+
"handrail",
78+
"highway",
79+
"incline",
80+
"lanes",
81+
"lit",
82+
"oneway",
83+
"ramp",
84+
"sac_scale",
85+
"segregated",
86+
"service",
87+
"smoothness",
88+
"tracktype",
89+
"width"
3990
)
40-
91+
4192
leisure_keys <- c("sauna", "swimming_pool")
42-
43-
motor_keys <- c("hov", "motor", "motorroad", "maxspeed", "traffic_calming", "vehicle", "direction", "lanes", "lane_markings")
44-
45-
nature_keys <- c("crop", "ele", "water", "intermittent", "plant", "leaf_type", "wetland", "water")
46-
47-
power_keys <- c("cables", "frequency", "generator", "power", "voltage", "rotor")
48-
93+
94+
motor_keys <- c(
95+
"hov",
96+
"motor",
97+
"motorroad",
98+
"maxspeed",
99+
"traffic_calming",
100+
"vehicle",
101+
"direction",
102+
"lanes",
103+
"lane_markings"
104+
)
105+
106+
nature_keys <- c(
107+
"crop",
108+
"ele",
109+
"water",
110+
"intermittent",
111+
"plant",
112+
"leaf_type",
113+
"wetland",
114+
"water"
115+
)
116+
117+
power_keys <- c(
118+
"cables",
119+
"frequency",
120+
"generator",
121+
"power",
122+
"voltage",
123+
"rotor"
124+
)
125+
49126
qa_keys <- c("fixme", "note", "ref")
50-
127+
51128
references_keys <- c("mappillary", "wikidata", "wikipedia")
52-
129+
53130
religion_keys <- c("denomination", "religion", "place_of_worship")
54-
55-
transport_keys <- c("electrified", "gauge", "light_rail", "NHS", "orientation", "park_ride", "railway", "route", "shoulder", "tunnel")
56-
131+
132+
transport_keys <- c(
133+
"electrified",
134+
"gauge",
135+
"light_rail",
136+
"NHS",
137+
"orientation",
138+
"park_ride",
139+
"railway",
140+
"route",
141+
"shoulder",
142+
"tunnel"
143+
)
144+
57145
df <- df |>
58146
dplyr::mutate(
59147
parent_key = dplyr::case_when(
60148
key %in% accessibility_keys ~ "Accessibility",
61149
stringr::str_detect(key, "wheelchair") ~ "Accessibility",
62150
stringr::str_detect(key, paste(care_keys, collapse = "|")) ~ "Care",
63-
stringr::str_detect(key, paste(contact_keys, collapse ="|")) ~ "Contact",
151+
stringr::str_detect(key, paste(contact_keys, collapse = "|")) ~
152+
"Contact",
64153
stringr::str_detect(key, "cycle|cyclability") ~ "Cycling",
65154
stringr::str_detect(key, "heritage") ~ "Heritage",
66155
key %in% motor_keys ~ "motor",
67-
stringr::str_detect(key, "maxspeed|vehicle|direction|fuel|lanes|parking") ~ "Motor",
156+
stringr::str_detect(
157+
key,
158+
"maxspeed|vehicle|direction|fuel|lanes|parking"
159+
) ~
160+
"Motor",
68161
stringr::str_detect(key, "foot|sidewalk|kerb") ~ "pedestrian",
69162
stringr::str_detect(key, "tourism") ~ "tourism",
70-
stringr::str_detect(key, "bus|naptan|public_transport|button_operated") ~ "Public transport",
71-
stringr::str_detect(key, paste(religion_keys, collapse = "|")) ~ "Religion"
163+
stringr::str_detect(
164+
key,
165+
"bus|naptan|public_transport|button_operated"
166+
) ~
167+
"Public transport",
168+
stringr::str_detect(key, paste(religion_keys, collapse = "|")) ~
169+
"Religion"
72170
),
73171
top_key = dplyr::case_when(
74172
stringr::str_detect(key, "addr") ~ "Addresses",
75173
# Amenities
76174
key %in% amenity_keys ~ "Amenities",
77175
stringr::str_detect(key, "amenity|brand|diet|shop") ~ "Amenities",
78-
parent_key %in% c("Care", "Contact", "Tourism", "Heritage", "Religion") ~ "Amenities",
176+
parent_key %in%
177+
c("Care", "Contact", "Tourism", "Heritage", "Religion") ~
178+
"Amenities",
79179
# Boundaries
80180
key %in% boundaries_keys ~ "Boundaries",
81181
# Buildings
82-
stringr::str_detect(key, "roof|building|architect|window") ~ "Buildings",
182+
stringr::str_detect(key, "roof|building|architect|window") ~
183+
"Buildings",
83184
# Crossings
84-
stringr::str_detect(key, "crossing|juntion|traffic_signals") ~ "Crossings",
185+
stringr::str_detect(key, "crossing|juntion|traffic_signals") ~
186+
"Crossings",
85187
# EDI
86188
key %in% edi_keys ~ "EDI",
87189
# External References
88-
stringr::str_detect(key, paste(references_keys, collapse = "|")) ~ "External references",
190+
stringr::str_detect(key, paste(references_keys, collapse = "|")) ~
191+
"External references",
89192
# Leisure
90193
key %in% leisure_keys ~ "Leisure",
91194
# Names
92-
stringr::str_detect(key, "name") & !stringr::str_detect(key, "housename") ~ "Names",
93-
stringr::str_detect(key, "leisure|sport") & !stringr::str_detect(key, "transport") ~ "Leisure",
195+
stringr::str_detect(key, "name") &
196+
!stringr::str_detect(key, "housename") ~
197+
"Names",
198+
stringr::str_detect(key, "leisure|sport") &
199+
!stringr::str_detect(key, "transport") ~
200+
"Leisure",
94201
# Natural resources
95202
key %in% nature_keys ~ "Natural Resources",
96-
stringr::str_starts(key, "natural|nature|water|river|tree|grass") ~ "Natural Resources",
203+
stringr::str_starts(key, "natural|nature|water|river|tree|grass") ~
204+
"Natural Resources",
97205
key %in% power_keys ~ "Power",
98206
stringr::str_detect(key, paste(power_keys, collapse = "|")) ~ "Power",
99207
# Quality Assurance
100208
key %in% qa_keys ~ "Quality Assurance",
101-
stringr::str_starts(key, "check_date|source|survey") ~ "Quality Assurance",
102-
stringr::str_detect(key, paste(qa_keys, collapse = "|")) ~ "Quality Assurance",
209+
stringr::str_starts(key, "check_date|source|survey") ~
210+
"Quality Assurance",
211+
stringr::str_detect(key, paste(qa_keys, collapse = "|")) ~
212+
"Quality Assurance",
103213
# Streets
104214
key %in% highway_keys ~ "Streets",
105215
stringr::str_detect(parent_key, "Cycling") ~ "Streets",
106-
stringr::str_detect(key, "pedestrian|kerb|sidewalk|surface|tactile_paving") ~ "Streets",
216+
stringr::str_detect(
217+
key,
218+
"pedestrian|kerb|sidewalk|surface|tactile_paving"
219+
) ~
220+
"Streets",
107221
# Transport
108222
key %in% transport_keys ~ "Transport",
109223
parent_key == "Public transport" ~ "Transport",
110224
stringr::str_detect(parent_key, "Motor") ~ "Transport",
111225
stringr::str_detect(key, "railway|traffic_|passenger") ~ "Transport"
112226
)
113227
)
114-
228+
115229
return(df)
116230
}

0 commit comments

Comments
 (0)