Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix summarise coding tools #75

Merged
merged 4 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions R/frequency-tables.R
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,20 @@ summarise_coding_tools <- function(data, type = list("knowledge", "access"), pro
"access_SPSS", "knowledge_stata", "access_stata",
"knowledge_matlab", "access_matlab")

levels <- c("Yes", "Don't know", "No")
if (type == "knowledge") {
levels <- c("Yes", "No", "Not required for my work")
} else {
levels <- c("Yes", "No", "Don't know")
}

labels <- c("R", "SQL", "SAS", "VBA", "Python", "SPSS", "Stata", "Matlab")

type <- match.arg(type, several.ok = TRUE)

questions <- questions[grepl(paste0(type, "_"), questions)]

frequencies <- calculate_freqs(data, questions, levels, labels, prop = prop)
frequencies <- calculate_freqs(data, questions, levels, labels, prop = prop) %>%
dplyr::arrange(match(name, c("Python", "R", "SQL", "Matlab", "SAS", "SPSS", "Stata", "VBA")))

return(frequencies)
}
Expand Down Expand Up @@ -424,7 +429,7 @@ summarise_rap_comp <- function(data) {
"Team open source code",
"Version control",
"Peer review",
"Development QA",
"Proportionate QA",
"Documentation",
"Functions",
"Unit testing",
Expand All @@ -438,7 +443,7 @@ summarise_rap_comp <- function(data) {
"open_code_score",
"version_control_score",
"peer_review_score",
"development_QA_score",
"proportionate_QA_score",
"doc_score",
"function_score",
"unit_test_score",
Expand Down
82 changes: 40 additions & 42 deletions tests/testthat/test-summarise_coding_tools.R
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
# Coding tools frequency tables (access or knowledge)

dummy_data <- data.frame(
knowledge_R = c("Yes", rep("No", 2), rep("Don't know", 3)),
access_R = c(rep("Yes", 2), "No", rep("Don't know", 3)),
knowledge_SQL = c(rep("Yes", 3), rep("No", 2), "Don't know"),
access_SQL = c("Yes", rep("No", 3), rep("Don't know", 2)),
knowledge_SAS = c(rep("Yes", 2), rep("No", 3), "Don't know"),
access_SAS = c(rep("Yes", 3), "No", rep("Don't know", 2)),
knowledge_VBA = c("Yes", rep("No", 2), rep("Don't know", 3)),
access_VBA = c(rep("Yes", 2), "No", rep("Don't know", 3)),
knowledge_python = c(rep("Yes", 3), rep("No", 2), "Don't know"),
access_python = c("Yes", rep("No", 3), rep("Don't know", 2)),
knowledge_SPSS = c(rep("Yes", 2), rep("No", 3), "Don't know"),
access_SPSS = c(rep("Yes", 3), "No", rep("Don't know", 2)),
knowledge_stata = c("Yes", rep("No", 2), rep("Don't know", 3)),
access_stata = c(rep("Yes", 2), "No", rep("Don't know", 3)),
knowledge_matlab = c(rep("Yes", 3), rep("No", 2), "Don't know"),
access_matlab = c("Yes", rep("No", 5), rep("Don't know", 0)) # Used to check zero counts aren't missing
knowledge_R = c("Yes", "No", "Not required for my work"),
access_R = c("Yes", "No", "Don't know"),
knowledge_SQL = c("Yes", "No", "Not required for my work"),
access_SQL = c("Yes", "No", "Don't know"),
knowledge_SAS = c("Yes", "No", "Not required for my work"),
access_SAS = c("Yes", "No", "Don't know"),
knowledge_VBA = c("Yes", "No", "Not required for my work"),
access_VBA = c("Yes", "No", "Don't know"),
knowledge_python = c("Yes", "No", "Not required for my work"),
access_python = c("Yes", "No", "Don't know"),
knowledge_SPSS = c("Yes", "No", "Not required for my work"),
access_SPSS = c("Yes", "No", "Don't know"),
knowledge_stata = c("Yes", "No", "Not required for my work"),
access_stata = c("Yes", "No", "Don't know"),
knowledge_matlab = c("Yes", "No", "No"),
access_matlab = c("Yes", "No", "No") # Used to check zero counts aren't missing
)

test_that("summarise_coding_tools missing data is handled correctly", {
Expand All @@ -33,19 +33,18 @@ test_that("summarise_coding_tools knowledge output is as expected", {

got_knowledge <- summarise_coding_tools(dummy_data, "knowledge")

expected_knowledge <- data.frame("name" = rep(c("Matlab",
"Python",
"R",
"SAS",
"SPSS",
"SQL",
"Stata",
"VBA"), each=3),
"value" = factor(rep(c("Yes", "Don't know", "No"), 8),
levels = c("Yes", "Don't know", "No")),
"n" = c(1/2, 1/6, 1/3, 1/2, 1/6, 1/3, 1/6, 1/2,
1/3, 1/3, 1/6, 1/2, 1/3, 1/6, 1/2, 1/2,
1/6, 1/3, 1/6, 1/2, 1/3, 1/6, 1/2, 1/3))
expected_knowledge <- data.frame(name = rep(c("Python",
"R",
"SQL",
"Matlab",
"SAS",
"SPSS",
"Stata",
"VBA"), each=3),
value = factor(rep(c("Yes", "No", "Not required for my work"), 8),
levels = c("Yes", "No", "Not required for my work")),
n = c(rep(1/3, times=9), 1/3, 2/3, 0, rep(1/3, times=12))
)

expect_equal(got_knowledge, expected_knowledge)

Expand All @@ -55,19 +54,18 @@ test_that("summarise_coding_tools access output is as expected", {

got_access <- summarise_coding_tools(dummy_data, "access")

expected_access <- data.frame("name" = rep(c("Matlab",
"Python",
"R",
"SAS",
"SPSS",
"SQL",
"Stata",
"VBA"), each=3),
"value" = factor(rep(c("Yes", "Don't know", "No"), 8),
levels = c("Yes", "Don't know", "No")),
"n" = c(1/6, 0, 5/6, 1/6, 1/3, 1/2, 1/3, 1/2,
1/6, 1/2, 1/3, 1/6, 1/2, 1/3, 1/6, 1/6,
1/3, 1/2, 1/3, 1/2, 1/6, 1/3, 1/2, 1/6))
expected_access <- data.frame(name = rep(c("Python",
"R",
"SQL",
"Matlab",
"SAS",
"SPSS",
"Stata",
"VBA"), each=3),
value = factor(rep(c("Yes", "No", "Don't know"), 8),
levels = c("Yes", "No", "Don't know")),
n = c(rep(1/3, times=9), 1/3, 2/3, 0, rep(1/3, times=12))
)

expect_equal(got_access, expected_access)

Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/test-summarise_languages_by_prof.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ knowledge_response <- rep(c(
NA,
"Yes",
"No",
"Don't know"),
"Not required for my work"),
each = 3, times = 6)

prof_response <- rep(c(
Expand Down Expand Up @@ -61,12 +61,12 @@ test_that("summarise_languages_by_prof output is as expected", {
expected <- data.frame(

lang = rep(c(
"Matlab",
"Python",
"R",
"SQL",
"Matlab",
"SAS",
"SPSS",
"SQL",
"Stata",
"VBA"),
times = 9),
Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/test-summarise_rap_comp.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ dummy_data <- data.frame(
open_code_score = rep(c(NA, 1, 0), times = 5),
version_control_score = rep(c(NA, 1, 0), times = 5),
peer_review_score = rep(c(NA, 1, 0), times = 5),
development_QA_score = rep(c(NA, 1, 0), times = 5),
proportionate_QA_score = rep(c(NA, 1, 0), times = 5),
doc_score = rep(c(NA, 1, 0), times = 5),
basic_rap_score = rep(c(NA, 1, 0), times = 5),
function_score = rep(c(NA, 1, 0), times = 5),
Expand Down Expand Up @@ -48,7 +48,7 @@ test_that("summarise_rap_comp output is as expected", {
"Team open source code",
"Version control",
"Peer review",
"Development QA",
"Proportionate QA",
"Documentation",
"Functions",
"Unit testing",
Expand All @@ -62,7 +62,7 @@ test_that("summarise_rap_comp output is as expected", {
"Team open source code",
"Version control",
"Peer review",
"Development QA",
"Proportionate QA",
"Documentation",
"Functions",
"Unit testing",
Expand Down