Skip to content

Commit

Permalink
Rearrange programming languages
Browse files Browse the repository at this point in the history
  • Loading branch information
ldavies99 committed Jan 5, 2024
1 parent efb0f90 commit 78370a9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
9 changes: 5 additions & 4 deletions R/frequency-tables.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -1152,19 +1153,19 @@ 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) %>%
dplyr::summarise(Freq = sum(prop_lang_knowledge), n = dplyr::n()) %>%
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)
}
Expand Down
16 changes: 8 additions & 8 deletions tests/testthat/test-summarise_coding_tools.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
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

0 comments on commit 78370a9

Please sign in to comment.