Project-level information
We store Crunch configuration in the project datalake object, which
you can inspect with dl_project_read(). The first step is
to set the Crunch folder ID and the
dataset name. These are usually set once per project
and reused by the rest of the workflow.
You can also call crunch_open() any time to open Crunch
in the browser. It tries to open the dataset if it
exists, falls back to the folder if it does not, and
finally opens the Crunch homepage if nothing is configured yet.
crunch_info()
crunch_open()
crunch_set_project("d1e9f017fd5a459e973adbbddf9852a1", check = TRUE)
crunch_set_dataset("[Package] Dataset Name")(Optional) Archive or delete existing Crunch dataset
If a dataset with the target name already exists in
the folder, crunch_upload() function
will not allow a new upload under the same name.
To keep the old dataset while freeing the name for a new upload, archive it – by default, dataset will be renamed with timestamp suffix.
Read survey data
We load the Crunch-ready survey data (srv_crunch). This
is the standardized survey structure used by our team and is a core
assumption of this package.
srv_crunch <- g6tr.survey::step_srv_read("crunch")Upload data
Upload the data to Crunch and connect to the dataset for further updates.
crunch_upload(srv_crunch)
crunch_ds <- crunch_connect()Gather variables
Use metadata to generate multiple-response gather rules. The rules
are written to crunch/gather.R and then sourced to apply
them.
crunch_guess_gather(overwrite = TRUE, open = FALSE)
source("crunch/gather.R")Organize Crunch folders
Generate folder rules based on metadata. The rules
are written to crunch/folders.R and then sourced to apply
them.
crunch_guess_folders(overwrite = TRUE, open = FALSE)
source("crunch/folders.R")Generate AI names
Create a dictionary from Crunch, generate AI-friendly display names, and write the dictionary to Google Drive for review.
crunch_dictionary <- crunch_get_dictionary(crunch_ds)
crunch_dictionary <- crunch_ai_names(crunch_dictionary)
crunch_write_dictionary(crunch_dictionary)Open the file in Drive and make any edits needed.
Update names and descriptions
crunch_dictionary <- crunch_read_dictionary()
crunch_apply_dictionary(crunch_ds, crunch_dictionary, apply_folder = TRUE)
# Hide variables
vars_to_hide <- crunch_get_dictionary(crunch_ds) |>
filter(!alias %in% crunch_dictionary$alias) |>
pull(alias)
vars_to_hide
for(iVariable in vars_to_hide) {
crunch::hideVariables(crunch_ds, iVariable)
}
crunch::hideVariables(crunch_ds, "response_id")Update Crunch Dictionary in Google Drive
crunch_dictionary <- crunch_get_dictionary(crunch_ds)
crunch_write_dictionary(crunch_dictionary)Add custom data
crunch_ds <- crunch_connect()
srv_additional <- dl_read("data/srv_additional")
crunch_add_data(crunch_ds, srv_additional)Create Crunch filters
Generate filter rules and apply them locally.
crunch_guess_filters(crunch_ds, vars = c("s_country", "s_employment"), overwrite = TRUE)
source("crunch/filters.R")Create Crunch dashboard
Use a dashboard spec built from your dictionary (or a filtered subset) and generate the Crunch automation script locally. Then run it against the dataset.
crunch_dictionary <- crunch_get_dictionary(crunch_ds)
crunch_dashboard_spec <- crunch_dictionary |>
filter(folder == "Screener") |>
rowwise() |>
mutate(
tile_code = as.character(crunch_generate_tile(
.data$alias,
.data$name,
.data$type,
.data$description
))
) |>
ungroup() |>
select(folder, tile_code)
crunch_generate_dashboard(crunch_dashboard_spec, name = "Dashboard", filters = c("s_country"), overwrite = TRUE)
runCrunchAutomation(crunch_ds, read_lines("crunch/Dashboard"))(Optional) Update Crunch Dictionary in Google Drive
We can update Crunch Dictionary again, just need to be careful to apply it after additional data is added.
crunch_dictionary <- crunch_get_dictionary(crunch_ds)
crunch_write_dictionary(crunch_dictionary)