I'm writing a function such that callers of this function can write schemas declaratively:
myschema <- Schema(
patientID = character,
temp = numeric,
treated = logical,
reason_treated = factor(levels=c('fever', 'chills', 'nausea'))
)
Later, I'd to be able to assemble dataframes using the types declared in this schema. I think the best candidate for this job is to use the metaprogramming features available in rlang
:
Schema = function(...) {
schematypes = rlang::enexprs(...)
}
However, most of the examples pertain to capturing the expression and thereafter using them as arguments to functions, rather than as functions themselves. That is, I'm finding it hard to capture the right side of the following expression:
patientID = character
and then later being able to evaluate it later as character(myvec)
, whenever I get myvec
. The same applies to the following:
reason_treated = factor(levels=c('fever', 'chills', 'nausea'))
which I would later like to evaluate as factor(myvec, levels=c('fever', 'chills', 'nausea'))
Thanks!