-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.Rhistory
More file actions
512 lines (512 loc) · 23 KB
/
.Rhistory
File metadata and controls
512 lines (512 loc) · 23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
check_utf8 <- function(df) {
# Identify columns with invalid UTF-8 characters
invalid_cols <- sapply(df, function(column) {
if (!is.character(column)) return(FALSE) # Skip non-character columns
any(sapply(column, function(x) {
if (is.na(x)) return(FALSE) # Ignore NA values
!identical(iconv(x, from = "UTF-8", to = "UTF-8"), x) # Check if conversion is needed
}))
})
# Extract the column names with invalid characters
bad_cols <- names(df)[invalid_cols]
# Output a message depending on whether non-UTF-8 characters were found
if (length(bad_cols) > 0) {
message("Non-UTF-8 characters detected in columns: ", paste(bad_cols, collapse = ", "))
} else {
message("No non-UTF-8 characters found.")
}
}
# Check the data for non-UTF-8 characters before conversion
check_utf8(data_in)
# Convert character columns from Latin1 encoding to UTF-8, removing problematic characters
data_in[] <- lapply(data_in, function(x) {
if (is.character(x)) {
iconv(x, from = "latin1", to = "UTF-8", sub = "") # Convert to UTF-8 and remove problematic characters
} else {
x
}
})
# Re-check the data for non-UTF-8 characters after the conversion
check_utf8(data_in)
# Convert 'date_of_drilling' column to Date type (assuming it's in m/d/y format)
data_in <- data_in %>%
mutate(date_of_drilling = mdy(date_of_drilling)) # mdy converts from month/day/year to Date type
# Reformat the date to d/m/y format (character format)
data_in <- data_in %>%
mutate(date_of_drilling = format(date_of_drilling, "%d/%m/%Y"))
# Check the updated date format
head(data_in$date_of_drilling)
# Convert 'date_of_drilling' column to Date type (assuming it's in m/d/y format)
data_in <- data_in %>%
# mdy converts from month/day/year to Date type
mutate(date_of_drilling = mdy(date_of_drilling))
# Reformat the date to d/m/y format (character format)
data_in <- data_in %>%
mutate(date_of_drilling = format(date_of_drilling, "%d/%m/%Y"))
# Description ------------------------------------------------------------------
# R script to process uploaded raw data into a tidy, analysis-ready data frame
# Load packages ----------------------------------------------------------------
## Run the following code in console if you don't have the packages
## install.packages(c("usethis", "fs", "here", "readr", "readxl", "openxlsx"))
library(usethis)
library(fs)
library(here)
library(readr)
library(dplyr)
library(readxl)
library(openxlsx)
library(lubridate)
# Load Data --------------------------------------------------------------------
# Load the necessary data from a CSV file
data_in <- readr::read_csv("data-raw/drilling survey.csv")
# (Optional) Read and clean the codebook if needed (commented out for now)
# codebook <- readxl::read_excel("data-raw/codebook.xlsx") %>%
# clean_names()
# Tidy data --------------------------------------------------------------------
# Remove rows where the 'latitude' column contains NULL (NA) values
data_in <- data_in %>%
filter(!is.na(latitude))
# Function to check for non-UTF-8 characters in character columns
check_utf8 <- function(df) {
# Identify columns with invalid UTF-8 characters
invalid_cols <- sapply(df, function(column) {
if (!is.character(column)) return(FALSE) # Skip non-character columns
any(sapply(column, function(x) {
if (is.na(x)) return(FALSE) # Ignore NA values
!identical(iconv(x, from = "UTF-8", to = "UTF-8"), x)
}))
})
# Extract the column names with invalid characters
bad_cols <- names(df)[invalid_cols]
# Output a message depending on whether non-UTF-8 characters were found
if (length(bad_cols) > 0) {
message("Non-UTF-8 characters detected in columns: ",
paste(bad_cols, collapse = ", "))
} else {
message("No non-UTF-8 characters found.")
}
}
# Check the data for non-UTF-8 characters before conversion
check_utf8(data_in)
# Convert character columns from Latin1 encoding to UTF-8, removing problematic
# characters
data_in[] <- lapply(data_in, function(x) {
if (is.character(x)) {
# Convert to UTF-8 and remove problematic characters
iconv(x, from = "latin1", to = "UTF-8", sub = "")
} else {
x
}
})
# Re-check the data for non-UTF-8 characters after the conversion
check_utf8(data_in)
# Convert 'date_of_drilling' column to Date type (assuming it's in m/d/y format)
data_in <- data_in %>%
mutate(date_of_drilling = mdy(date_of_drilling))
# Reformat the date to d/m/y format (character format)
data_in <- data_in %>%
mutate(date_of_drilling = format(date_of_drilling, "%d/%m/%Y"))
# Assign data to a variable
drillingdata <- data_in
# Export Data ------------------------------------------------------------------
usethis::use_data(drillingdata, overwrite = TRUE)
fs::dir_create(here::here("inst", "extdata"))
readr::write_csv(drillingdata,
here::here("inst", "extdata", paste0("drillingdata", ".csv")))
openxlsx::write.xlsx(drillingdata,
here::here("inst", "extdata", paste0("drillingdata",
".xlsx")))
setup_dictionary()
setup_roxygen()
devtools::document()
devtools::check()
devtools::install()
use_author(
given = "Emmanuel",
family = "Mhango",
role = c("aut", "cre"),
email = "[email protected]",
comment = c(ORCID = "0000-0003-3197-6244")
)
use_author(given = "Jamie", family = "Rattray", role = "aut")
use_author(given = "Shaun", family = "MacLeod", role = "aut")
use_author(given = "Given", family = "Nyasulu", role = "aut")
use_author(given = "Temwani", family = "Chisunkha", role = "aut")
use_author(given = "Gloria", family = "Musopole", role = "aut")
use_author(given = "Agnes", family = "Hamis", role = "aut")
use_author(given = "Feston", family = "Bwanyula", role = "aut")
update_description()
devtools::document()
devtools::check()
devtools::install()
add_metadata()
install.packages("dataspice")
library(dataspice)
add_metadata()
library(dataspice)
add_metadata()
create_spice()
library(washr)
library(tidyverse)
add_creator(name="Emmanuel Mhango", email="[email protected]", affiliation="Openwashdata, baseflow")
add_metadata()
devtools::document()
devtools::check()
devtools::check()
devtools::install()
setup_readme()
# Display a chart for the boreholes drilled per year ---------------------------
# Convert 'date_of_drilling' to Date format and extract the year
drillingdata$year <- year(mdy(drillingdata$date_of_drilling))
# Count number of boreholes drilled per year
boreholes_per_year <- drillingdata %>%
filter(!is.na(year)) %>%
group_by(year) %>%
summarise(boreholes_drilled = n())
# Create the bar plot
ggplot(boreholes_per_year, aes(x = factor(year), y = boreholes_drilled)) +
geom_col(fill = "#2c7fb8") +
theme_minimal() +
labs(
title = "Boreholes Drilled Per Year",
x = "Year",
y = "Number of Boreholes Drilled"
)
devtools::build_readme()
devtools::build_readme()
devtools::build_readme()
# Description ------------------------------------------------------------------
# R script to process uploaded raw data into a tidy, analysis-ready data frame
# Load packages ----------------------------------------------------------------
## Run the following code in console if you don't have the packages
## install.packages(c("usethis", "fs", "here", "readr", "readxl", "openxlsx"))
library(usethis)
library(fs)
library(here)
library(readr)
library(dplyr)
library(readxl)
library(openxlsx)
library(lubridate)
# Load Data --------------------------------------------------------------------
# Load the necessary data from a CSV file
data_in <- readr::read_csv("data-raw/drilling survey.csv")
# (Optional) Read and clean the codebook if needed (commented out for now)
# codebook <- readxl::read_excel("data-raw/codebook.xlsx") %>%
# clean_names()
# Tidy data --------------------------------------------------------------------
# Remove rows where the 'latitude' column contains NULL (NA) values
data_in <- data_in %>%
filter(!is.na(latitude))
# Function to check for non-UTF-8 characters in character columns
check_utf8 <- function(df) {
# Identify columns with invalid UTF-8 characters
invalid_cols <- sapply(df, function(column) {
if (!is.character(column)) return(FALSE) # Skip non-character columns
any(sapply(column, function(x) {
if (is.na(x)) return(FALSE) # Ignore NA values
!identical(iconv(x, from = "UTF-8", to = "UTF-8"), x)
}))
})
# Extract the column names with invalid characters
bad_cols <- names(df)[invalid_cols]
# Output a message depending on whether non-UTF-8 characters were found
if (length(bad_cols) > 0) {
message("Non-UTF-8 characters detected in columns: ",
paste(bad_cols, collapse = ", "))
} else {
message("No non-UTF-8 characters found.")
}
}
# Check the data for non-UTF-8 characters before conversion
check_utf8(data_in)
# Convert character columns from Latin1 encoding to UTF-8, removing problematic
# characters
data_in[] <- lapply(data_in, function(x) {
if (is.character(x)) {
# Convert to UTF-8 and remove problematic characters
iconv(x, from = "latin1", to = "UTF-8", sub = "")
} else {
x
}
})
# Re-check the data for non-UTF-8 characters after the conversion
check_utf8(data_in)
# Convert 'date_of_drilling' column to Date type (assuming it's in m/d/y format)
data_in <- data_in %>%
mutate(date_of_drilling = mdy(date_of_drilling))
# Reformat the date to d/m/y format (character format)
data_in <- data_in %>%
mutate(date_of_drilling = format(date_of_drilling, "%d/%m/%Y"))
# Assign data to a variable
drillingdata <- data_in
# Export Data ------------------------------------------------------------------
usethis::use_data(drillingdata, overwrite = TRUE)
fs::dir_create(here::here("inst", "extdata"))
readr::write_csv(drillingdata,
here::here("inst", "extdata", paste0("drillingdata", ".csv")))
openxlsx::write.xlsx(drillingdata,
here::here("inst", "extdata", paste0("drillingdata",
".xlsx")))
# Display a chart for the boreholes drilled per year ---------------------------
# Convert 'date_of_drilling' to Date format and extract the year
drillingdata$year <- year(mdy(drillingdata$date_of_drilling))
# Count number of boreholes drilled per year
boreholes_per_year <- drillingdata %>%
filter(!is.na(year)) %>%
group_by(year) %>%
summarise(boreholes_drilled = n())
# Create the bar plot
ggplot(boreholes_per_year, aes(x = factor(year), y = boreholes_drilled)) +
geom_col(fill = "#2c7fb8") +
theme_minimal() +
labs(
title = "Boreholes Drilled Per Year",
x = "Year",
y = "Number of Boreholes Drilled"
)
# Description ------------------------------------------------------------------
# R script to process uploaded raw data into a tidy, analysis-ready data frame
# Load packages ----------------------------------------------------------------
## Run the following code in console if you don't have the packages
## install.packages(c("usethis", "fs", "here", "readr", "readxl", "openxlsx"))
library(usethis)
library(fs)
library(here)
library(readr)
library(dplyr)
library(readxl)
library(openxlsx)
library(lubridate)
# Load Data --------------------------------------------------------------------
# Load the necessary data from a CSV file
data_in <- readr::read_csv("data-raw/drilling survey.csv")
# (Optional) Read and clean the codebook if needed (commented out for now)
# codebook <- readxl::read_excel("data-raw/codebook.xlsx") %>%
# clean_names()
# Tidy data --------------------------------------------------------------------
# Remove rows where the 'latitude' column contains NULL (NA) values
data_in <- data_in %>%
filter(!is.na(latitude))
# Function to check for non-UTF-8 characters in character columns
check_utf8 <- function(df) {
# Identify columns with invalid UTF-8 characters
invalid_cols <- sapply(df, function(column) {
if (!is.character(column)) return(FALSE) # Skip non-character columns
any(sapply(column, function(x) {
if (is.na(x)) return(FALSE) # Ignore NA values
!identical(iconv(x, from = "UTF-8", to = "UTF-8"), x)
}))
})
# Extract the column names with invalid characters
bad_cols <- names(df)[invalid_cols]
# Output a message depending on whether non-UTF-8 characters were found
if (length(bad_cols) > 0) {
message("Non-UTF-8 characters detected in columns: ",
paste(bad_cols, collapse = ", "))
} else {
message("No non-UTF-8 characters found.")
}
}
# Check the data for non-UTF-8 characters before conversion
check_utf8(data_in)
# Convert character columns from Latin1 encoding to UTF-8, removing problematic
# characters
data_in[] <- lapply(data_in, function(x) {
if (is.character(x)) {
# Convert to UTF-8 and remove problematic characters
iconv(x, from = "latin1", to = "UTF-8", sub = "")
} else {
x
}
})
# Re-check the data for non-UTF-8 characters after the conversion
check_utf8(data_in)
# Convert 'date_of_drilling' column to Date type (assuming it's in m/d/y format)
data_in <- data_in %>%
mutate(date_of_drilling = mdy(date_of_drilling))
# Reformat the date to d/m/y format (character format)
data_in <- data_in %>%
mutate(date_of_drilling = format(date_of_drilling, "%d/%m/%Y"))
# Assign data to a variable
drillingdata <- data_in
# Export Data ------------------------------------------------------------------
usethis::use_data(drillingdata, overwrite = TRUE)
fs::dir_create(here::here("inst", "extdata"))
readr::write_csv(drillingdata,
here::here("inst", "extdata", paste0("drillingdata", ".csv")))
openxlsx::write.xlsx(drillingdata,
here::here("inst", "extdata", paste0("drillingdata",
".xlsx")))
# Display a chart for the boreholes drilled per year ---------------------------
# Convert 'date_of_drilling' to Date format and extract the year
drillingdata$year <- year(mdy(drillingdata$date_of_drilling))
# Count number of boreholes drilled per year
boreholes_per_year <- drillingdata %>%
filter(!is.na(year)) %>%
group_by(year) %>%
summarise(boreholes_drilled = n())
# Create the bar plot
ggplot(boreholes_per_year, aes(x = factor(year), y = boreholes_drilled)) +
geom_col(fill = "red") +
theme_minimal() +
labs(
title = "Boreholes Drilled Per Year",
x = "Year",
y = "Number of Boreholes Drilled"
)
devtools::build_readme()
devtools::build_readme()
library(stringr)
# Example descriptions
descriptions <- c(
"The date when drilling was carried out.",
"Indicates whether the water point has been created (\"Yes\" or \"No\").",
"The geographic latitude of the drilling site.",
"The geographic longitude of the drilling site.",
"The intended use of the water point (e.g., for drinking, irrigation, etc.).",
"Any additional usage of the water point not covered by the standard categories.",
"The source of funding for the drilling project (e.g., government, NGO, private).",
"Indicates whether the WRB1A form for the drilling project has been completed.",
"Whether a contract has been signed for the drilling project.",
"Whether an agreement with the community has been made regarding the water point.",
"Indicates whether a government supervisor is available during the drilling process.",
"The name of the contractor responsible for the drilling.",
"Indicates whether the driller is licensed to carry out the drilling.",
"Indicates whether the staff involved in the drilling project are experienced.",
"The model of the drilling rig used for the project.",
"Specifications of the compressor used during the drilling.",
"The condition of the drilling equipment (e.g., new, used, needs repair).",
"The condition of the safety features of the equipment.",
"The overall capability of the equipment used in drilling.",
"Specifications related to the equipment’s capabilities.",
"Indicates whether personal protective equipment (PPE) is available for the workers.",
"An image of the drilling equipment used in the project.",
"The methodology used to select the drilling location.",
"Indicates whether a hydrogeological study has been done at the drilling site.",
"Indicates whether a geophysical survey has been done at the site.",
"The minimum distance (in meters) the drilling site is from contamination sources (50 meters or more).",
"The distance of the drilling site from any contamination sources.",
"Indicates whether the site is accessible for drilling.",
"Indicates whether the site is suitable for drilling (e.g., no obstacles).",
"The distance of the drilling site from nearby water bodies (rivers, lakes, etc.).",
"A photograph of the drilling site location.",
"Indicates whether there is a perimeter fence around the site for security.",
"Indicates whether the staff are protected from potential risks (e.g., fencing, safety measures).",
"Indicates whether a parking area is available for vehicles at the site.",
"Indicates whether there is easy emergency access to the site.",
"Indicates whether the site is located at a suitable distance from power lines.",
"The distance from a reference point or key feature to the drilling site.",
"Indicates whether the materials are stored safely at the site.",
"Indicates whether chemicals are stored safely on-site.",
"Indicates whether a first aid kit is available at the site.",
"Indicates whether a fire extinguisher is available at the site.",
"Indicates whether the welfare facilities (toilets, etc.) are adequate for the workers.",
"The distance of the welfare facilities (e.g., toilets) from the drilling site.",
"Indicates whether the preliminary setup activities for drilling have been completed.",
"Indicates whether the drilling rig has been set up properly.",
"A reference point used for the drilling site’s coordinates or location.",
"The height of the reference point above or below sea level.",
"The method used to level the drilling rig at the site.",
"Any issues encountered during the setup of the drilling rig.",
"Boolean indicating whether any setup problems were encountered.",
"The length of the drill rods used in the drilling operation.",
"The minimum diameter of the borehole (177mm).",
"The minimum diameter of the borehole for drilling.",
"Indicates whether the casing materials are stored properly.",
"The location where the casing materials are stored.",
"Indicates why the casing materials were not stored properly (if applicable).",
"An index value for referencing in the dataset.",
"The number of rods used during the drilling process.",
"The starting depth (in meters) for the first drilling operation.",
"The ending depth (in meters) for the first drilling operation.",
"The method used for circulating fluids during drilling.",
"The type of drill bit used during drilling.",
"The diameter of the borehole in millimeters.",
"The total time taken for drilling (in minutes).",
"Comments related to the drilling process.",
"The depth at which water was first encountered during drilling (in meters).",
"An index value for referencing in the dataset.",
"The starting depth (in meters) for the second drilling operation.",
"The ending depth (in meters) for the second drilling operation.",
"The material used for the temporary casing in the borehole.",
"The diameter of the temporary casing (in millimeters).",
"An index value for referencing in the dataset.",
"The starting depth (in meters) for the third drilling operation.",
"The ending depth (in meters) for the third drilling operation.",
"The type of rock or soil encountered at the drilling site.",
"The color of the rock or soil encountered during drilling.",
"The level of weathering observed in the rock or soil encountered.",
"A description of the grain size of the soil or rock.",
"The sorting characteristics of the soil or rock (e.g., well-sorted, poorly sorted).",
"Any additional description related to the geological formation or drilling process.",
"The name of the geological formation encountered during drilling.",
"An index value for referencing in the dataset.",
"The depth of the hole for the first section of drilling (in meters).",
"The discharge rate of water from the borehole (in liters per minute or other units).",
"The method used to measure the discharge rate of the borehole.",
"The electrical conductivity of the water at the first measurement point (in mS/cm).",
"The total dissolved solids (TDS) in the water at the first measurement point (in mg/L).",
"The pH of the water at the first measurement point.",
"The temperature of the water at the first measurement point (in Celcius).",
"Comments related to the first measurement point (e.g., water quality, observations).",
"The total depth of the borehole (in meters).",
"The water level in the borehole after drilling (in meters).",
"The date when measurements were taken for water level, discharge, etc.",
"Whether the borehole is suitable for further use (e.g., for a pump, additional development).",
"Whether a design is available for installing equipment in the borehole.",
"Whether the design was agreed upon by the driller.",
"The date when the casing was installed in the borehole.",
"Whether the materials used in the drilling process meet established standards.",
"Whether the materials used in the drilling process were pre-inspected.",
"An index value for referencing in the dataset.",
"The inner diameter of the casing (in millimeters).",
"The outer diameter of the casing (in millimeters).",
"The material used for the first section of the casing.",
"The size of the slot aperture in the casing (in millimeters).",
"Whether an end cap was fitted to the casing.",
"Whether centralizers were fitted in the borehole casing.",
"The type of connection used for the casing segments (e.g., threaded, welded).",
"An index value for referencing in the dataset.",
"The starting depth (in meters) for the fourth drilling operation.",
"The ending depth (in meters) for the fourth drilling operation.",
"The inner diameter of the casing (in millimeters).",
"The material of the casing used for the borehole.",
"The strength of the casing material used in the borehole.",
"Indicates whether the casing is slotted for water entry.",
"Indicates whether the gravel pack is clean and free of contaminants.",
"The quality of the gravel pack used in the borehole.",
"An index value for referencing in the dataset.",
"The starting depth (in meters) for the fifth drilling operation.",
"The ending depth (in meters) for the fifth drilling operation.",
"The minimum grain size of the gravel used in the pack (in millimeters).",
"The maximum grain size of the gravel used in the pack (in millimeters).",
"The final level of the gravel pack after installation (in meters).",
"The static water level before development work begins (in meters).",
"An index value for referencing in the dataset.",
"The total duration of the drilling process (in hours or days).",
"The method used for the drilling process (e.g., rotary, percussion).",
"An index value for referencing in the dataset.",
"The amount of time taken for specific drilling operations (in minutes).",
"The depth at which the lift occurs during the drilling operation (in meters).",
"The discharge rate of water from the borehole at a later measurement point (in liters per minute).",
"The electrical conductivity of the water at a later measurement point (in mS/cm).",
"The total dissolved solids (TDS) in the water at a later measurement point (in mg/L).",
"The pH of the water at a later measurement point.",
"The temperature of the water at a later measurement point (in Celcius).",
"The turbidity of the water (cloudiness) measured in NTU (Nephelometric Turbidity Units).",
"The amount or type of sediment in the water at a later measurement point.",
"The static water level after development work is done (in meters).",
"A summary of the final borehole design, including all technical and engineering details."
)
# Check for invalid UTF-8 characters
invalid_utf8 <- descriptions[!str_detect(descriptions, "^[\\x00-\\x7F]*$")]
invalid_utf8
devtools::build_readme()
devtools::document()
devtools::check()
devtools::install()
devtools::build_readme()
devtools::document()
devtools::check()
devtools::install()