Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error by Interacting with tibble 1.x #17

Closed
caayala opened this issue Sep 8, 2017 · 5 comments
Closed

Error by Interacting with tibble 1.x #17

caayala opened this issue Sep 8, 2017 · 5 comments
Labels

Comments

@caayala
Copy link

caayala commented Sep 8, 2017

From: https://blog.rstudio.com/2016/03/24/tibble-1-0-0/

Interacting with legacy code
A handful of functions are don’t work with tibbles because they expect df[, 1] to return a vector, not a data frame. If you encounter one of these functions, use as.data.frame() to turn a tibble back to a data frame.

With this correction, impute_shd and impute_rhd functions are working as expected.

library(tibble)
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
library(simputation)

dat <- as_tibble(iris)
# empty a few fields
dat[1:3,1] <- dat[3:7,2] <- dat[8:10,5] <- NA

dat %>% impute_shd(Sepal.Length ~ Sepal.Width + Species) %>% head(3)
#> Error: Can't use matrix or array for column indexing
dat %>% impute_rhd(Sepal.Length ~ Sepal.Width + Species) %>% head(3)
#> Error: Can't use matrix or array for column indexing
@markvanderloo
Copy link
Owner

Thanks for this, will have a look.
-M

@BobMuenchen
Copy link

I just ran into this same problem. Switching to a standard data frame fixes it for impute_knn and impute_lm too. I'm pretty sure I'm using the latest R and I just installed simputation from source today.

sessionInfo()
R version 3.5.1 (2018-07-02)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.1252

attached base packages:
[1] stats graphics grDevices utils datasets methods
[7] base

other attached packages:
[1] forcats_0.3.0 stringr_1.3.1 dplyr_0.7.6
[4] purrr_0.2.5 readr_1.1.1 tidyr_0.8.1
[7] tibble_1.4.2 ggplot2_3.0.0 tidyverse_1.2.1
[10] simputation_0.2.2

loaded via a namespace (and not attached):
[1] Rcpp_0.12.18 cellranger_1.1.0 pillar_1.3.0
[4] compiler_3.5.1 gower_0.1.2 plyr_1.8.4
[7] bindr_0.1.1 tools_3.5.1 rpart_4.1-13
[10] lubridate_1.7.4 jsonlite_1.5 gtable_0.2.0
[13] jmvcore_0.9.2.0 nlme_3.1-137 lattice_0.20-35
[16] jmv_0.9.2.0 pkgconfig_2.0.1 rlang_0.2.1
[19] cli_1.0.0 rstudioapi_0.7 haven_1.1.2
[22] bindrcpp_0.2.2 withr_2.1.2 xml2_1.2.0
[25] httr_1.3.1 knitr_1.20 hms_0.4.2
[28] grid_3.5.1 tidyselect_0.2.4 glue_1.3.0
[31] R6_2.2.2 fansi_0.3.0 readxl_1.1.0
[34] modelr_0.1.2 magrittr_1.5 scales_1.0.0
[37] backports_1.1.2 MASS_7.3-50 rvest_0.3.2
[40] assertthat_0.2.0 colorspace_1.3-2 utf8_1.1.4
[43] stringi_1.1.7 lazyeval_0.2.1 munsell_0.5.0
[46] broom_0.5.0 crayon_1.3.4 rjson_0.2.20

@markvanderloo
Copy link
Owner

This really is an tibble issue. The tidyverse developers made the deliberate choice to create an object that uses S3 inheritance from a data.frame without respecting existing methods.

Not only is this bad engineering. It is extremely unpolite to the many FOSS developers that are now facing 'bug reports' due to their market dominance.

The workaround is to transform tibble objects to data.frame before feeding them to impute_ functions. It's good practice to make type conversions explicit.

@caayala
Copy link
Author

caayala commented Mar 13, 2020

Thanks for your explanation.
Can you just add a better error message to avoid futures bug reports?

@markvanderloo
Copy link
Owner

That's something to consider. One issue is that I have also seen tibble-related errors in simputation that ultimately came from non-tibble compatibility in one of the dependencies. So I could protect against that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants