Skip to contents

Adds rType column with smart defaults if missing. This enables language-specific type coercion (R types like integer, double, factor).

Usage

apply_rtype_defaults(details)

Arguments

details

Data frame. Variable details metadata.

Value

Data frame with rType column added (if missing) or validated (if present).

Details

Default rType values

If rType column is missing, defaults are applied based on variable type:

  • continuous/cont"double"

  • categorical/cat"factor"

  • date"Date"

  • logical"logical"

  • Unknown → "character"

Valid rType values

  • "integer": Whole numbers (age, counts, years)

  • "double": Decimal numbers (BMI, income, percentages)

  • "factor": Categorical with levels

  • "character": Text codes

  • "logical": TRUE/FALSE values

  • "Date": Date objects

  • "POSIXct": Datetime objects

Examples

if (FALSE) { # \dontrun{
# Missing rType - defaults applied
details <- data.frame(
  variable = "age",
  typeEnd = "cont",
  recStart = "[18, 100]"
)
details <- apply_rtype_defaults(details)
# details$rType is now "double"

# Existing rType - preserved
details <- data.frame(
  variable = "age",
  typeEnd = "cont",
  rType = "integer"
)
details <- apply_rtype_defaults(details)
# details$rType remains "integer"
} # }