0

Is there a way to replace only the assessment split in an rset object?

I tried the following:

library(rsample)
library(dplyr)

splits <- vfold_cv(mtcars)

assessment(splits$splits[[1]])
#>               mpg cyl  disp  hp drat    wt  qsec vs am gear carb
#> Mazda RX4    21.0   6 160.0 110 3.90 2.620 16.46  0  1    4    4
#> Merc 450SE   16.4   8 275.8 180 3.07 4.070 17.40  0  0    3    3
#> Merc 450SLC  15.2   8 275.8 180 3.07 3.780 18.00  0  0    3    3
#> Lotus Europa 30.4   4  95.1 113 3.77 1.513 16.90  1  1    5    2

assessment(splits$splits[[1]]) <- assessment(splits$splits[[1]]) %>% slice(1)
#> Error in assessment(splits$splits[[1]]) <- assessment(splits$splits[[1]]) %>% : could not find function "assessment<-"

Created on 2020-02-14 by the reprex package (v0.3.0)

I know I can extract the assessment and analysis splits and then work with them, but I want to update the rset object instead.

Giovanni Colitti
  • 1,982
  • 11
  • 24
  • `assessment()` and `analysis()` are functions, which [you can check out if you like](https://github.com/tidymodels/rsample/blob/4fdbd6c05a6ad928831b9a0273b5a2b0f18f9e05/R/rsplit.R#L105); it may help if you share a bit more about your goal here, i.e. why you want to manipulate data in the splits. – Julia Silge Feb 16 '20 at 00:22
  • I'm familiar with those functions; they aren't what I'm after. The goal is to build a function that returns an rset object. So I'd like to 1) better understand rset objects and 2) determine if I can alter them directly – Giovanni Colitti Feb 16 '20 at 04:46
  • 1
    Currently the constructors aren't exposed, but you can [see what other folks are doing](https://github.com/tidymodels/rsample/issues/40), and perhaps chime in with your interest/opinion/use case so we can understand better. – Julia Silge Feb 16 '20 at 16:55

0 Answers0