assume_var_classes: Assume variable classes in data

View source: R/import_export.R

assume_var_classesR Documentation

Assume variable classes in data

Description

Classes/data types of data variables are assumed with this function and exported to a .csv file for amendment. Any incorrect classes can then be corrected and imported using import_var_classes. Character and factor variables with exactly two unique non-missing values are labelled "binary". Character variables with more than two but no more than factor_threshold unique non-missing values are labelled "factor".

Usage

assume_var_classes(data, out_file = NULL, factor_threshold = 5L)

Arguments

data

data frame

out_file

file where variables and their assumed classes are stored for user verification.

factor_threshold

integer. Maximum number of unique non-missing values for a character variable to be labelled "factor". Variables with exactly 2 unique values are labelled "binary" regardless of this threshold. Set to 0 or NULL to disable factor detection. Default: 5.

Value

Writes a .csv file containing the variables and their assumed data types / classes.

See Also

import_var_classes

Examples

# example below assumes incorrectly for several variables
tmp = tempfile(fileext = ".csv")
data(example_data)
assume_var_classes(example_data, tmp)

eHDPrep documentation built on Oct. 21, 2026, 5:10 p.m.