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

make_splits() does not work on empty assessment indices #188

Closed
4 tasks done
tjmahr opened this issue Sep 25, 2020 · 3 comments · Fixed by #189
Closed
4 tasks done

make_splits() does not work on empty assessment indices #188

tjmahr opened this issue Sep 25, 2020 · 3 comments · Fixed by #189
Labels
bug an unexpected problem or unintended behavior

Comments

@tjmahr
Copy link

tjmahr commented Sep 25, 2020

If you are filing a bug, make sure these boxes are checked before submitting your issue— thank you!

  • Start a new R session
  • Install the latest version of of the package: update.packages(oldPkgs="rsample", ask=FALSE)
  • Write a minimal reproducible example
  • run sessionInfo() and add the results to the issue. Even better would be to use the sessioninfo package's session_info().

Minimal, reproducible example:

I am trying to make my own rset function for bootstrap sampling groups in a grouped dataframes. But I run into an issue when the assessment rows empty. When making the reprex, I also discovered that I had to use 5L instead of 5 for the index.

rsample::make_splits(
  list(
    analysis = 1:5,
    assessment = NA
  ),
  data.frame(x = 1:5)
)
#> Error in UseMethod("complement"): no applicable method for 'complement' applied to an object of class "rsplit"

rsample::make_splits(
  list(
    analysis = 1:5,
    assessment = integer(0)
  ),
  data.frame(x = 1:5)
)
#> Error in UseMethod("complement"): no applicable method for 'complement' applied to an object of class "rsplit"

rsample::make_splits(
  list(
    analysis = 1:4,
    assessment = 5
  ),
  data.frame(x = 1:5)
)
#> Error: `out_id` must be a positive integer vector.

rsample::make_splits(
  list(
    analysis = 1:4,
    assessment = 5L
  ),
  data.frame(x = 1:5)
)
#> <Analysis/Assess/Total>
#> <4/1/5>

Created on 2020-09-25 by the reprex package (v0.3.0)

Session info
devtools::session_info()
#> - Session info ---------------------------------------------------------------
#>  setting  value                       
#>  version  R version 4.0.2 (2020-06-22)
#>  os       Windows 10 x64              
#>  system   x86_64, mingw32             
#>  ui       RTerm                       
#>  language (EN)                        
#>  collate  English_United States.1252  
#>  ctype    English_United States.1252  
#>  tz       America/Chicago             
#>  date     2020-09-25                  
#> 
#> - Packages -------------------------------------------------------------------
#>  package     * version date       lib source                            
#>  assertthat    0.2.1   2019-03-21 [1] CRAN (R 4.0.2)                    
#>  backports     1.1.10  2020-09-15 [1] CRAN (R 4.0.2)                    
#>  callr         3.4.4   2020-09-07 [1] CRAN (R 4.0.2)                    
#>  cli           2.0.2   2020-02-28 [1] CRAN (R 4.0.2)                    
#>  codetools     0.2-16  2018-12-24 [1] CRAN (R 4.0.0)                    
#>  crayon        1.3.4   2017-09-16 [1] CRAN (R 4.0.2)                    
#>  desc          1.2.0   2018-05-01 [1] CRAN (R 4.0.2)                    
#>  devtools      2.3.2   2020-09-18 [1] CRAN (R 4.0.2)                    
#>  digest        0.6.25  2020-02-23 [1] CRAN (R 4.0.2)                    
#>  dplyr         1.0.2   2020-08-18 [1] CRAN (R 4.0.2)                    
#>  ellipsis      0.3.1   2020-05-15 [1] CRAN (R 4.0.2)                    
#>  evaluate      0.14    2019-05-28 [1] CRAN (R 4.0.2)                    
#>  fansi         0.4.1   2020-01-08 [1] CRAN (R 4.0.2)                    
#>  fs            1.5.0   2020-07-31 [1] CRAN (R 4.0.2)                    
#>  furrr         0.1.0   2018-05-16 [1] CRAN (R 4.0.2)                    
#>  future        1.19.1  2020-09-22 [1] CRAN (R 4.0.2)                    
#>  generics      0.0.2   2018-11-29 [1] CRAN (R 4.0.2)                    
#>  globals       0.13.0  2020-09-17 [1] CRAN (R 4.0.2)                    
#>  glue          1.4.2   2020-08-27 [1] CRAN (R 4.0.2)                    
#>  highr         0.8     2019-03-20 [1] CRAN (R 4.0.2)                    
#>  htmltools     0.5.0   2020-06-16 [1] CRAN (R 4.0.2)                    
#>  knitr         1.30    2020-09-22 [1] CRAN (R 4.0.2)                    
#>  lifecycle     0.2.0   2020-03-06 [1] CRAN (R 4.0.2)                    
#>  listenv       0.8.0   2019-12-05 [1] CRAN (R 4.0.2)                    
#>  magrittr      1.5     2014-11-22 [1] CRAN (R 4.0.2)                    
#>  memoise       1.1.0   2017-04-21 [1] CRAN (R 4.0.2)                    
#>  pillar        1.4.6   2020-07-10 [1] CRAN (R 4.0.2)                    
#>  pkgbuild      1.1.0   2020-07-13 [1] CRAN (R 4.0.2)                    
#>  pkgconfig     2.0.3   2019-09-22 [1] CRAN (R 4.0.2)                    
#>  pkgload       1.1.0   2020-05-29 [1] CRAN (R 4.0.2)                    
#>  prettyunits   1.1.1   2020-01-24 [1] CRAN (R 4.0.2)                    
#>  processx      3.4.4   2020-09-03 [1] CRAN (R 4.0.2)                    
#>  ps            1.3.4   2020-08-11 [1] CRAN (R 4.0.2)                    
#>  purrr         0.3.4   2020-04-17 [1] CRAN (R 4.0.2)                    
#>  R6            2.4.1   2019-11-12 [1] CRAN (R 4.0.2)                    
#>  remotes       2.2.0   2020-07-21 [1] CRAN (R 4.0.2)                    
#>  rlang         0.4.7   2020-07-09 [1] CRAN (R 4.0.2)                    
#>  rmarkdown     2.3.2   2020-07-06 [1] Github (rstudio/rmarkdown@ff1b279)
#>  rprojroot     1.3-2   2018-01-03 [1] CRAN (R 4.0.2)                    
#>  rsample       0.0.8   2020-09-23 [1] CRAN (R 4.0.2)                    
#>  sessioninfo   1.1.1   2018-11-05 [1] CRAN (R 4.0.2)                    
#>  stringi       1.5.3   2020-09-09 [1] CRAN (R 4.0.2)                    
#>  stringr       1.4.0   2019-02-10 [1] CRAN (R 4.0.2)                    
#>  testthat      2.3.2   2020-03-02 [1] CRAN (R 4.0.2)                    
#>  tibble        3.0.3   2020-07-10 [1] CRAN (R 4.0.2)                    
#>  tidyr         1.1.2   2020-08-27 [1] CRAN (R 4.0.2)                    
#>  tidyselect    1.1.0   2020-05-11 [1] CRAN (R 4.0.2)                    
#>  usethis       1.6.3   2020-09-17 [1] CRAN (R 4.0.2)                    
#>  vctrs         0.3.4   2020-08-29 [1] CRAN (R 4.0.2)                    
#>  withr         2.3.0   2020-09-22 [1] CRAN (R 4.0.2)                    
#>  xfun          0.17    2020-09-09 [1] CRAN (R 4.0.2)                    
#>  yaml          2.2.1   2020-02-01 [1] CRAN (R 4.0.0)                    
#> 
#> [1] C:/Users/Tristan/Documents/R/win-library/4.0
#> [2] C:/Program Files/R/R-4.0.2/library
@juliasilge
Copy link
Member

For some context setting here, what do you plan or expect to do when the assessment set is empty?

@tjmahr
Copy link
Author

tjmahr commented Sep 25, 2020

To match what bootstraps() does. See <split [N/0]> when the assessment set is empty.

set.seed(1)
df <- data.frame(x = c(1, 2))

splits <- rsample::bootstraps(df, 5)
splits
#> # Bootstrap sampling 
#> # A tibble: 5 x 2
#>   splits        id        
#>   <list>        <chr>     
#> 1 <split [2/0]> Bootstrap1
#> 2 <split [2/1]> Bootstrap2
#> 3 <split [2/0]> Bootstrap3
#> 4 <split [2/1]> Bootstrap4
#> 5 <split [2/1]> Bootstrap5

rsample::assessment(splits[["splits"]][[1]])
#> [1] x
#> <0 rows> (or 0-length row.names)

I get that bootstrapping is weird, compared to N fold or leave-one-out sampling, because it does not guarantee a holdout sample for assessment.

Created on 2020-09-25 by the reprex package (v0.3.0)

@juliasilge juliasilge added the bug an unexpected problem or unintended behavior label Sep 25, 2020
@github-actions
Copy link

This issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with a reprex https://reprex.tidyverse.org) and link to this issue.

@github-actions github-actions bot locked and limited conversation to collaborators Feb 21, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug an unexpected problem or unintended behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants