Skip to content

Commit

Permalink
Department names (#68)
Browse files Browse the repository at this point in the history
* Updated department name cleaning for wave5

* Added data engineers to prof list

* Added docs/ to gitignore

* Update clean_departments test

---------

Co-authored-by: ldavies99 <[email protected]>
  • Loading branch information
CHCRowley and ldavies99 authored Dec 1, 2023
1 parent 27f4950 commit d672e73
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ temp/
*.csv
*.rda
exploratory_scripts/
docs/
4 changes: 3 additions & 1 deletion R/data_cleaning.R
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,15 @@ rename_cols <- function(data) {

clean_departments <- function(data) {

data$department[grepl("forest research", tolower(data$other_department_name))] <- "Forestry Commission"
data$department[data$department == "Foreign, Commonwealth & Development Office (excl. agencies)"] <- "Foreign, Commonwealth and Development Office (excl. agencies)"

data$department[data$workplace == "NHS"] <- "NHS"

defra_orgs <- c(
"Department for Environment, Food and Rural Affairs (excl. agencies)",
"Forestry Commission",
"Forest Research",
"Forestry England",
"Animal and Plant Health Agency",
"Centre for Environment, Fisheries and Aquaculture Science",
"Rural Payments Agency",
Expand Down
3 changes: 3 additions & 0 deletions R/render.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ create_filtered_pages <- function(data, type = c("professions", "departments"),

if (type == "professions") {
prof_cols <- c(
"prof_DE",
"prof_DS",
"prof_DDAT",
"prof_GAD",
Expand All @@ -52,6 +53,7 @@ create_filtered_pages <- function(data, type = c("professions", "departments"),
)

prof_names <- c(
"government data engineers",
"government data scientists",
"digital and data profession (DDAT)",
"government actuary's department (GAD)",
Expand All @@ -63,6 +65,7 @@ create_filtered_pages <- function(data, type = c("professions", "departments"),
)

filenames <- c(
"data-engineers.qmd",
"data-scientists.qmd",
"digital-and-data.qmd",
"government-actuarys-department.qmd",
Expand Down
18 changes: 11 additions & 7 deletions tests/testthat/test-clean_departments.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,36 @@ test_that("clean_departments output is as expected", {

dummy_data <- data.frame(department = c(NA,
"test",
"test",
"Foreign, Commonwealth & Development Office (excl. agencies)",
"Department for Environment, Food and Rural Affairs (excl. agencies)",
"Forestry Commission",
"Forest Research",
"Forestry England",
"Animal and Plant Health Agency",
"Centre for Environment, Fisheries and Aquaculture Science",
"Rural Payments Agency",
"Environment Agency",
"Marine Management Organisation",
"Natural England"),
other_department_name = c(NA, "Forest research", rep("test", 8)),
workplace = c(NA, "test", "NHS", rep("test", 7)))
workplace = c(NA, "NHS", rep("test", 11)))

got <- clean_departments(dummy_data)

expected <- data.frame(department = c(NA,
"Forestry Commission",
"NHS",
"Foreign, Commonwealth and Development Office (excl. agencies)",
"Department for Environment, Food and Rural Affairs (excl. agencies)",
"Forestry Commission",
"Forest Research",
"Forestry England",
"Animal and Plant Health Agency",
"Centre for Environment, Fisheries and Aquaculture Science",
"Rural Payments Agency",
"Environment Agency",
"Marine Management Organisation",
"Natural England"),
other_department_name = c(NA, "Forest research", rep("test", 8)),
workplace = c(NA, "test", "NHS", rep("test", 7)),
defra = c(FALSE, TRUE, FALSE, rep(TRUE, 7)))
workplace = c(NA, "NHS", rep("test", 11)),
defra = c(rep(FALSE, 3), rep(TRUE, 10)))

expect_equal(got, expected)

Expand Down

0 comments on commit d672e73

Please sign in to comment.