Skip to content

[CTIS QSF tools] Generate changelog from diffing codebook #1630

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

Merged
merged 13 commits into from
Jun 8, 2022
Merged
10 changes: 5 additions & 5 deletions facebook/qsf-tools/combine_changelogs_eu.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ combine_changelogs <- function(path_to_changelog_eu,
old_version = col_double()
)) %>%
mutate(
eu_version = "EU"
eu_noneu = "EU"
)

changelog_noneu <- read_csv(path_to_changelog_noneu, col_types = cols(
Expand All @@ -31,21 +31,21 @@ combine_changelogs <- function(path_to_changelog_eu,
old_version = col_double()
)) %>%
mutate(
eu_version = "Non-EU"
eu_noneu = "Non-EU"
)

# Using rbind here to raise an error if columns differ between the existing
# changelog and the new wave data.
changelog_with_duplicates <- rbind(changelog_eu, changelog_noneu)

count_duplicated_rows <- changelog_with_duplicates %>% group_by(across(c(-eu_version))) %>% summarize(count = n())
count_duplicated_rows <- changelog_with_duplicates %>% group_by(across(c(-eu_noneu))) %>% summarize(count = n())
changelog <- changelog_with_duplicates %>% left_join(count_duplicated_rows)
changelog$eu_version[changelog$count == 2] <- "Both"
changelog$eu_noneu[changelog$count == 2] <- "Both"

# Sort so that items with missing type (non-Qualtrics fields) are at the top.
# Drop duplicates.
changelog <- changelog %>%
arrange(variable_name, eu_version) %>%
arrange(variable_name, eu_noneu) %>%
select(-count) %>%
distinct()

Expand Down
12 changes: 6 additions & 6 deletions facebook/qsf-tools/combine_codebooks_eu.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,30 @@ combine_codebooks <- function(path_to_codebook_eu,
version = col_double()
)) %>%
mutate(
eu_version = "EU"
eu_noneu = "EU"
)

codebook_noneu <- read_csv(path_to_codebook_noneu, col_types = cols(
.default = col_character(),
version = col_double()
)) %>%
mutate(
eu_version = "Non-EU"
eu_noneu = "Non-EU"
)

# Using rbind here to raise an error if columns differ between the existing
# codebook and the new wave data.
codebook_with_duplicates <- rbind(codebook_eu, codebook_noneu)

count_duplicated_rows <- codebook_with_duplicates %>% group_by(across(c(-eu_version))) %>% summarize(count = n())
count_duplicated_rows <- codebook_with_duplicates %>% group_by(across(c(-eu_noneu))) %>% summarize(count = n())
codebook <- codebook_with_duplicates %>% left_join(count_duplicated_rows)
codebook$eu_version[codebook$count == 2] <- "Both"
codebook$eu_noneu[codebook$count == 2] <- "Both"

# Sort so that items with missing type (non-Qualtrics fields) are at the top.
# Drop duplicates.
codebook <- codebook %>%
arrange(!is.na(.data$question_type), variable, version, eu_version) %>%
select(-count) %>%
arrange(!is.na(.data$question_type), variable, version, eu_noneu) %>%
select(-count, -replaces) %>%
distinct()

return(codebook)
Expand Down
Loading