Skip to content

Commit

Permalink
Remove non-coders from proportion (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
ldavies99 authored Jan 11, 2024
1 parent 9b9e6e1 commit fd07cbf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
3 changes: 3 additions & 0 deletions R/frequency-tables.R
Original file line number Diff line number Diff line change
Expand Up @@ -1144,6 +1144,9 @@ summarise_heard_of_RAP_by_prof <- function(data) {
#' @export

summarise_os_vs_prop <- function(data) {

data <- dplyr::filter(data, !is.na(code_freq), code_freq != "Never")

data$open_source_lang_knowledge <- ifelse(
data$knowledge_python == "Yes" | data$knowledge_R == "Yes",
TRUE, FALSE
Expand Down
18 changes: 10 additions & 8 deletions tests/testthat/test-summarise_os_vs_prop.R
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@

dummy_data <- data.frame(year = rep(c(2020, 2021, 2022), each=32),
knowledge_python = rep(rep(c("Yes", "No"), each=16), times=3),
knowledge_R = rep(rep(c("Yes", "No"), each=8), times=6),
knowledge_SAS = rep(rep(c("Yes", "No"), each=4), times=12),
knowledge_SPSS = rep(rep(c("Yes", "No"), each=2), times=24),
knowledge_stata = rep(c("Yes", "No"), times=48))
n=192
dummy_data <- data.frame(year = rep(c(2020, 2021, 2022), each=n/3),
code_freq = rep(c("Never", "Sometimes"), each=n/6, times=n/32),
knowledge_python = rep(c("Yes", "No"), each=n/12, times=n/16),
knowledge_R = rep(c("Yes", "No"), each=n/24, times=n/8),
knowledge_SAS = rep(c("Yes", "No"), each=n/48, times=n/4),
knowledge_SPSS = rep(c("Yes", "No"), each=n/96, times=n/2),
knowledge_stata = rep(c("Yes", "No"), each=n/192, times=n))

test_that("summarise_os_vs_prop missing data is handled correctly", {

Expand All @@ -23,8 +25,8 @@ test_that("summarise_os_vs_prop output is as expected", {
expected <- data.frame(lang_type = factor(rep(c("Open Source", "Proprietary"), each=3),
levels = c("Open Source", "Proprietary")),
year = rep(c("2020", "2021", "2022"), times=2),
Freq = rep(c(24, 28), each=3),
n = rep(32, times=6)) %>%
Freq = rep(c(48, 56), each=3),
n = rep(64, times=6)) %>%
get_ci(freq_col = 3, n_col = 4)

expect_equal(got, expected)
Expand Down

0 comments on commit fd07cbf

Please sign in to comment.