markvanderloo / simputation

Making imputation easy
GNU General Public License v3.0
89 stars 11 forks source link

providing a variable name by a variable containing the string #22

Closed heejongkim closed 4 years ago

heejongkim commented 5 years ago

Hi, I wonder if this package can handle !!as.name-like way to provide variable name by providing the variable with the string.

Ex. IMPUTED_VARIABLES ~ MODEL_SPECIFICATION [ | GROUPING_VARIABLES ]

instead of directly specifying the column name: abundance ~ mean(abundance) | group

I'd like to do something like: abundance_column_name <- "abundance" !!as.name(abundance_column_name) ~ mean(!!as.name(abundance_column_name)) | group

will it be possible with the current implementation?

best, hee jong kim

markvanderloo commented 5 years ago

Well, I'm not familiar with rlang but you can always construct a character-based formula and convert that. For example:

abundance_column_name <- "abundance"
frm <- paste(abundance_column_name, " ~ mean(", abundance_column_name ")")
impute_proxy(data, as.formula(frm))

The crux is the as.formula function that converts an appropriate string to a formula object.