diff --git a/R/frequency-tables.R b/R/frequency-tables.R index 2fd33bb..e6178df 100644 --- a/R/frequency-tables.R +++ b/R/frequency-tables.R @@ -134,7 +134,8 @@ summarise_coding_tools <- function(data, type = list("knowledge", "access"), pro 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) } @@ -1152,7 +1153,7 @@ summarise_os_vs_prop <- function(data) { data.frame %>% get_ci(freq_col = 2, n_col = 3) - os_freqs <- cbind(lang_type = "Open Source", os_freqs) + os_freqs <- cbind(lang_type = "open source", os_freqs) prop_freqs <- data %>% dplyr::group_by(year) %>% @@ -1160,11 +1161,11 @@ summarise_os_vs_prop <- function(data) { data.frame %>% get_ci(freq_col = 2, n_col = 3) - prop_freqs <- cbind(lang_type = "Proprietary", prop_freqs) + prop_freqs <- cbind(lang_type = "proprietary", prop_freqs) grouped_lang_freqs <- rbind(os_freqs, prop_freqs) grouped_lang_freqs$year <- as.character(grouped_lang_freqs$year) - grouped_lang_freqs$lang_type <- factor(grouped_lang_freqs$lang_type, levels = c("Open Source", "Proprietary")) + grouped_lang_freqs$lang_type <- factor(grouped_lang_freqs$lang_type, levels = c("open source", "proprietary")) return(grouped_lang_freqs) } diff --git a/tests/testthat/test-summarise_coding_tools.R b/tests/testthat/test-summarise_coding_tools.R index 477a8ff..4288e4b 100644 --- a/tests/testthat/test-summarise_coding_tools.R +++ b/tests/testthat/test-summarise_coding_tools.R @@ -33,17 +33,17 @@ 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", + expected_knowledge <- data.frame(name = rep(c("Python", "R", + "SQL", + "Matlab", "SAS", "SPSS", - "SQL", "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(1/3, 2/3, 0, rep(1/3, times=21)) + n = c(rep(1/3, times=9), 1/3, 2/3, 0, rep(1/3, times=12)) ) expect_equal(got_knowledge, expected_knowledge) @@ -54,17 +54,17 @@ 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", + expected_access <- data.frame(name = rep(c("Python", "R", + "SQL", + "Matlab", "SAS", "SPSS", - "SQL", "Stata", "VBA"), each=3), value = factor(rep(c("Yes", "No", "Don't know"), 8), levels = c("Yes", "No", "Don't know")), - n = c(1/3, 2/3, 0, rep(1/3, times=21)) + n = c(rep(1/3, times=9), 1/3, 2/3, 0, rep(1/3, times=12)) ) expect_equal(got_access, expected_access) diff --git a/tests/testthat/test-summarise_languages_by_prof.R b/tests/testthat/test-summarise_languages_by_prof.R index 74b0045..41393c4 100644 --- a/tests/testthat/test-summarise_languages_by_prof.R +++ b/tests/testthat/test-summarise_languages_by_prof.R @@ -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( @@ -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),