| Title: | Search and Examine Variables Across Survey Datasets |
|---|---|
| Description: | Search for variables across multiple survey datasets, examine variable properties (labels, values, missingness), and explore variable context within datasets. Useful for navigating complex survey data with many variables and understanding variable relationships and metadata. |
| Authors: | Malo Raballand [aut, cre] |
| Maintainer: | Malo Raballand <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.0 |
| Built: | 2026-05-07 18:32:29 UTC |
| Source: | https://github.com/cran/surveysearch |
Display detailed information about a specific variable including its label, class, missing values, value labels, and summary statistics.
examine_variable(var_name, data, verbose = TRUE)examine_variable(var_name, data, verbose = TRUE)
var_name |
Character string. Name of the variable to examine. |
data |
Data frame containing the variable. |
verbose |
Logical. If TRUE, print detailed information to console. |
Invisibly returns a list with elements:
Variable name
Variable label
Variable class
Number of unique non-missing values
Number of missing values
df <- data.frame(age = c(25, 30, 35)) attr(df$age, "label") <- "Age in years" examine_variable("age", data = df)df <- data.frame(age = c(25, 30, 35)) attr(df$age, "label") <- "Age in years" examine_variable("age", data = df)
Search for variables matching a pattern across multiple datasets. Searches both variable names and variable labels.
search_variables(pattern, data_list, datasets_info = NULL)search_variables(pattern, data_list, datasets_info = NULL)
pattern |
A regular expression or literal string to match (case-insensitive). |
data_list |
A named list of data frames to search. |
datasets_info |
Optional data frame with column |
Invisibly returns a data frame with columns:
Name of the dataset
Variable name
Variable label or "No label" if missing
Either "Variable Name" or "Label Text"
# Create sample data with labels df1 <- data.frame(age = 1:3, income = c(50000, 60000, 70000)) attr(df1$age, "label") <- "Age in years" attr(df1$income, "label") <- "Annual income" df2 <- data.frame(education = c("HS", "BA", "MA"), employment = c("Yes", "No", "Yes")) attr(df2$education, "label") <- "Education level" attr(df2$employment, "label") <- "Currently employed" # Create a named list of data frames (NOT a list of text names!) my_datasets <- list(survey_2023 = df1, survey_2024 = df2) # Search across multiple datasets search_variables("age", data_list = my_datasets) # Search for pattern in labels search_variables("income", data_list = my_datasets) # WRONG - do not do this: # wrong_list <- list(c("survey_2023", "survey_2024")) # List of text! # search_variables("age", data_list = wrong_list) # Will fail!# Create sample data with labels df1 <- data.frame(age = 1:3, income = c(50000, 60000, 70000)) attr(df1$age, "label") <- "Age in years" attr(df1$income, "label") <- "Annual income" df2 <- data.frame(education = c("HS", "BA", "MA"), employment = c("Yes", "No", "Yes")) attr(df2$education, "label") <- "Education level" attr(df2$employment, "label") <- "Currently employed" # Create a named list of data frames (NOT a list of text names!) my_datasets <- list(survey_2023 = df1, survey_2024 = df2) # Search across multiple datasets search_variables("age", data_list = my_datasets) # Search for pattern in labels search_variables("income", data_list = my_datasets) # WRONG - do not do this: # wrong_list <- list(c("survey_2023", "survey_2024")) # List of text! # search_variables("age", data_list = wrong_list) # Will fail!
Display a variable along with specified number of variables before and after it in dataset order.
show_variable_context(var_name, data, before = 5, after = 5, verbose = TRUE)show_variable_context(var_name, data, before = 5, after = 5, verbose = TRUE)
var_name |
Character string. Name of the variable to show context for. |
data |
Data frame containing the variable. |
before |
Integer. Number of variables to show before the target variable. Default is 5. |
after |
Integer. Number of variables to show after the target variable. Default is 5. |
verbose |
Logical. If TRUE, print formatted output. |
Invisibly returns a data frame with columns:
Position of the variable in the dataset
Variable name
Variable label
Indicator showing target variable
df <- data.frame(a = 1, b = 2, c = 3, d = 4, e = 5, f = 6, g = 7, h = 8) # Show 5 before and 5 after (default) show_variable_context("e", data = df) # Show only 2 before and 2 after show_variable_context("e", data = df, before = 2, after = 2) # Show 10 before and 3 after show_variable_context("e", data = df, before = 10, after = 3)df <- data.frame(a = 1, b = 2, c = 3, d = 4, e = 5, f = 6, g = 7, h = 8) # Show 5 before and 5 after (default) show_variable_context("e", data = df) # Show only 2 before and 2 after show_variable_context("e", data = df, before = 2, after = 2) # Show 10 before and 3 after show_variable_context("e", data = df, before = 10, after = 3)