Why do we need a copy of the data for the return value of initial_split()?

Why do we need a copy of the data for the return value of initial_split()?The way I think of it, just returning the index is fine. Is there any other purpose for returning a copy of the data?


hotels <-
read_csv("https://tidymodels.org/start/case-study/hotels.csv") %>%
mutate(across(where(is.character), as.factor))

splits <- initial_split(hotels, strata = children)

initial_split's purpose is to facilitate training() and testing() functions like in the example

car_split <- initial_split(mtcars)
train_data <- training(car_split)
test_data <- testing(car_split)

If you don't like the API thats fine, you can do otherwise, but thats the API :smiley:

for what its worth, because of Rs copy-on-write approach, initial split will not tie up significant memory, unless it or the original data are altered. However ; the training and testing data sets creations will perform a copy action, as they are modifications of the initial data.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.