Skip to content

Commit

Permalink
replace .data with strings in tidyselect expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
mikabr committed Oct 12, 2023
1 parent c3285d7 commit c28e214
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 35 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Title: Accessing the Wordbank Database
Description: Connecting to Wordbank, an open repository for developmental
vocabulary data. For more information on the underlying data, see
<http://wordbank.stanford.edu>.
Version: 1.0.0.9000
Version: 1.0.0.9001
Authors@R: c(
person("Mika", "Braginsky", email = "[email protected]", role = c("aut", "cre")),
person("Daniel", "Yurovsky", email = "[email protected]", role = "ctb"),
Expand Down
6 changes: 3 additions & 3 deletions R/aoa.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ fit_aoa <- function(instrument_data, measure = "produces", method = "glm",
# understands = !is.na(.data$value) &
# (.data$value == "understands" | .data$value == "produces")
# ) %>%
dplyr::select(-.data$value) %>%
dplyr::select(-"value") %>%
tidyr::gather("measure_name", "value",
.data$produces, .data$understands) %>%
dplyr::filter(.data$measure_name == measure) %>%
Expand Down Expand Up @@ -94,7 +94,7 @@ fit_aoa <- function(instrument_data, measure = "produces", method = "glm",

instrument_aoa <- instrument_fits %>%
dplyr::mutate(aoa = .data$fit_data %>% purrr::map_dbl(compute_aoa)) %>%
dplyr::select(-.data$data, -.data$fit_data)
dplyr::select(-"data", -"fit_data")

item_cols <- c("num_item_id", "item_id", "item_kind", "item_definition",
"category", "lexical_category", "lexical_class", "uni_lemma",
Expand All @@ -107,6 +107,6 @@ fit_aoa <- function(instrument_data, measure = "produces", method = "glm",

instrument_aoa %>%
dplyr::left_join(item_data, by = "num_item_id") %>%
dplyr::select(-.data$num_item_id)
dplyr::select(-"num_item_id")

}
9 changes: 4 additions & 5 deletions R/crossling.R
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,8 @@ get_crossling_data <- function(uni_lemmas, db_args = NULL) {

item_data <- get_item_data(db_args = db_args) %>%
dplyr::filter(.data$uni_lemma %in% uni_lemmas) %>%
dplyr::select(.data$language, .data$form, .data$form_type, .data$item_id,
.data$item_kind, .data$item_definition, .data$uni_lemma,
.data$lexical_category)
dplyr::select("language", "form", "form_type", "item_id", "item_kind",
"item_definition", "uni_lemma", "lexical_category")
if (nrow(item_data) == 0) {
message("No items found for uni_lemma")
return()
Expand All @@ -112,10 +111,10 @@ get_crossling_data <- function(uni_lemmas, db_args = NULL) {

item_summary <- item_data %>%
dplyr::mutate(lang = .data$language, frm = .data$form) %>%
tidyr::nest(df = -c(.data$lang, .data$frm)) %>%
tidyr::nest(df = -c("lang", "frm")) %>%
dplyr::transmute(summary = .data$df %>%
purrr::map(~safe_summarise_items(., db_args)$result)) %>%
tidyr::unnest(.data$summary)
tidyr::unnest(cols = "summary")

suppressWarnings(DBI::dbDisconnect(src))
return(item_summary)
Expand Down
6 changes: 3 additions & 3 deletions R/quantiles.R
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ fit_vocab_quantiles <- function(vocab_data, measure, group,
return(NULL)
})
})) %>%
dplyr::select(-.data$group_label) %>%
dplyr::select(-"group_label") %>%
dplyr::filter(purrr::map_lgl(.data$model, ~!is.null(.))) %>%
dplyr::ungroup()
if (nrow(vocab_models) == 0) return(NULL)
Expand All @@ -95,8 +95,8 @@ fit_vocab_quantiles <- function(vocab_data, measure, group,

vocab_fits <- vocab_models %>%
dplyr::mutate(predicted = purrr::map(.data$model, get_predicted)) %>%
dplyr::select(-.data$data, -.data$model) %>%
tidyr::unnest(cols = .data$predicted) %>%
dplyr::select(-"data", -"model") %>%
tidyr::unnest(cols = "predicted") %>%
dplyr::rename("{{measure}}" := .data$predicted) %>%
dplyr::mutate(quantile = factor(.data$quantile))

Expand Down
43 changes: 20 additions & 23 deletions R/wordbankr.R
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,7 @@ get_datasets <- function(language = NULL, form = NULL, admin_data = FALSE,
if (is.null(src)) return()

instruments <- get_instruments(db_args = db_args) %>%
dplyr::select(.data$instrument_id, .data$language, .data$form,
.data$form_type)
dplyr::select("instrument_id", "language", "form", "form_type")

suppressWarnings(
dataset_data <- get_common_table(src, "dataset") %>%
Expand All @@ -174,7 +173,7 @@ get_datasets <- function(language = NULL, form = NULL, admin_data = FALSE,
dataset_origin_name = .data$dataset_origin_id) %>%
dplyr::mutate(longitudinal = as.logical(.data$longitudinal)) %>%
dplyr::select(dplyr::starts_with("dataset"), dplyr::everything()) %>%
dplyr::select(-.data$instrument_id)
dplyr::select(-"instrument_id")

if (admin_data) {
suppressWarnings(
Expand Down Expand Up @@ -265,9 +264,8 @@ get_administration_data <- function(language = NULL, form = NULL,
if (is.null(src)) return()

datasets <- get_datasets(db_args = db_args) %>%
dplyr::select(.data$dataset_id, .data$dataset_name,
.data$dataset_origin_name, .data$language, .data$form,
.data$form_type)
dplyr::select("dataset_id", "dataset_name", "dataset_origin_name",
"language", "form", "form_type")

select_cols <- c("data_id", "date_of_test", "age", "comprehension",
"production", "is_norming",
Expand Down Expand Up @@ -301,11 +299,10 @@ get_administration_data <- function(language = NULL, form = NULL,
dplyr::mutate(data_id = as.numeric(.data$data_id),
is_norming = as.logical(.data$is_norming)) %>%
dplyr::left_join(datasets, by = "dataset_id") %>%
dplyr::select(-.data$dataset_id) %>%
dplyr::select(.data$data_id, .data$date_of_test, .data$age,
.data$comprehension, .data$production, .data$is_norming,
dplyr::starts_with("dataset"), .data$language, .data$form,
.data$form_type, dplyr::everything())
dplyr::select(-"dataset_id") %>%
dplyr::select("data_id", "date_of_test", "age", "comprehension",
"production", "is_norming", dplyr::starts_with("dataset"),
"language", "form", "form_type", dplyr::everything())
)

if (include_demographic_info) {
Expand All @@ -316,11 +313,11 @@ get_administration_data <- function(language = NULL, form = NULL,
dplyr::mutate(caregiver_education = factor(
.data$education_level, levels = .data$education_level)
) %>%
dplyr::select(.data$caregiver_education_id, .data$caregiver_education)
dplyr::select("caregiver_education_id", "caregiver_education")

admins <- admins %>%
dplyr::left_join(educations, by = "caregiver_education_id") %>%
dplyr::select(-.data$caregiver_education_id) %>%
dplyr::select(-"caregiver_education_id") %>%
dplyr::relocate(.data$caregiver_education, .after = .data$birth_order) %>%
dplyr::mutate(sex = factor(.data$sex, levels = c("F", "M", "O"),
labels = c("Female", "Male", "Other")),
Expand All @@ -341,9 +338,9 @@ get_administration_data <- function(language = NULL, form = NULL,
if (include_language_exposure) {
language_exposures <- get_common_table(src, "language_exposure") %>%
dplyr::semi_join(admins_tbl, by = "administration_id") %>%
dplyr::select(-.data$id) %>%
dplyr::select(-"id") %>%
dplyr::collect() %>%
tidyr::nest(language_exposures = -.data$administration_id)
tidyr::nest(language_exposures = -"administration_id")
admins <- admins %>%
dplyr::left_join(language_exposures, by = "administration_id")
}
Expand All @@ -355,9 +352,9 @@ get_administration_data <- function(language = NULL, form = NULL,
dplyr::semi_join(admins_tbl, by = "child_id") %>%
dplyr::left_join(health_conditions,
by = c("healthcondition_id" = "id")) %>%
dplyr::select(-.data$id, -.data$healthcondition_id) %>%
dplyr::select(-"id", -"healthcondition_id") %>%
dplyr::collect() %>%
tidyr::nest(health_conditions = -.data$child_id)
tidyr::nest(health_conditions = -"child_id")
admins <- admins %>%
dplyr::left_join(child_health_conditions, by = "child_id")
}
Expand All @@ -368,7 +365,7 @@ get_administration_data <- function(language = NULL, form = NULL,
dplyr::filter(.data$age >= .data$age_min, .data$age <= .data$age_max)

admins <- admins %>%
dplyr::select(-.data$age_min, -.data$age_max, -.data$administration_id)
dplyr::select(-"age_min", -"age_max", -"administration_id")
return(admins)

}
Expand Down Expand Up @@ -492,7 +489,7 @@ get_instrument_data <- function(language, form, items = NULL,
administration_info <- administration_info %>%
dplyr::filter(.data$language == input_language,
.data$form == input_form) %>%
dplyr::select(-.data$language, -.data$form, -.data$form_type)
dplyr::select(-"language", -"form", -"form_type")
}

if ("logical" %in% class(item_info)) {
Expand All @@ -505,15 +502,15 @@ get_instrument_data <- function(language, form, items = NULL,
dplyr::filter(.data$language == input_language, .data$form == input_form,
is.element(.data$item_id, items)) %>%
dplyr::mutate(num_item_id = strip_item_id(.data$item_id)) %>%
dplyr::select(-.data$item_id)
dplyr::select(-"item_id")

item_data_cols <- colnames(item_data)

instrument_data <- instrument_table %>%
dplyr::select(.data$basetable_ptr_id, !!items_quo) %>%
dplyr::select("basetable_ptr_id", !!items_quo) %>%
dplyr::collect() %>%
dplyr::mutate(data_id = as.numeric(.data$basetable_ptr_id)) %>%
dplyr::select(-.data$basetable_ptr_id) %>%
dplyr::select(-"basetable_ptr_id") %>%
tidyr::gather("item_id", "value", !!items_quo) %>%
dplyr::mutate(num_item_id = strip_item_id(.data$item_id)) %>%
dplyr::left_join(item_data, by = "num_item_id") %>%
Expand All @@ -537,7 +534,7 @@ get_instrument_data <- function(language, form, items = NULL,
if ("logical" %in% class(item_info) && !item_info) {
instrument_data <- instrument_data %>% dplyr::select(-{{ item_data_cols }})
} else {
instrument_data <- instrument_data %>% dplyr::select(-.data$num_item_id)
instrument_data <- instrument_data %>% dplyr::select(-"num_item_id")
}

DBI::dbDisconnect(src)
Expand Down

0 comments on commit c28e214

Please sign in to comment.