markvanderloo / simputation

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

Back tick `variable names` fail in imputation formulae #19

Closed MilesMcBain closed 4 years ago

MilesMcBain commented 7 years ago

Here's a reprex that highlights the issue:

library(tibble)
library(magrittr)
library(simputation)
tibble::tribble(
  ~`a col`, ~`b col`,
         1, NA,
         3, 3,
         5, 5,
         7, 7
) %>% 
  as.data.frame() %>%
  impute_knn(`b col` ~ `a col`, k = 3)  
#> Error in `[.data.frame`(dat, imp_vars): undefined columns selected

tibble::tribble(
  ~a.col, ~b.col,
  1, NA,
  3, 3,
  5, 5,
  7, 7
) %>% 
  as.data.frame() %>%
  impute_knn(b.col ~ a.col, k = 3)  
#>   a.col b.col
#> 1     1     3
#> 2     3     3
#> 3     5     5
#> 4     7     7

I think the issue is caused by the extraction of formula components in get_imputed and get_predictors . I see 'get_imputed(dat, `b col` ~ `a col`)' returns "`b col`" rather than "b col" which is required to index the column.

markvanderloo commented 7 years ago

That's a bug. Thanks for the report!

markvanderloo commented 4 years ago

Finally fixed this. As a token of gratitude, you have been immortalized in the NEWS file :)