I'm building dozens of predictive models in an effort to identify a champion model. I'm working with gigabytes of data, so tracking run time is important.
I'd like to build all my models in a list-type format, so I don't have to manage all the different model names within the Global Environment. However, it seems that the only way to get timings per model is to have separate named objects.
Here's a basic method that approaches what I'm looking for:
library(tidyverse)
# Basic Approach
Time_1 <- system.time(
Model_1 <- lm(am ~ disp, mtcars)
)
Time_2 <- system.time(
Model_2 <- lm(am ~ disp + cyl, mtcars)
)
# etc. for dozens more
Time_List <-
mget(ls(pattern = "Time")) %>%
bind_rows()
However, as you can see, I have to manually name each model and time record. What I'm looking for is something similar to the table produced with the following code, where "xxx" is an actual record of run time.
# Tribble Output
tribble(
~Model_Name, ~Model_Function, ~Run_Time,
"Model_1", lm(am ~ disp, mtcars), "xxx",
"Model_2", lm(am ~ disp + cyl, mtcars), "xxx"
)
# A tibble: 2 × 3
Model_Name Model_Function Run_Time
<chr> <list> <chr>
1 Model_1 <S3: lm> xxx
2 Model_2 <S3: lm> xxx
I'd appreciate any input provided, regardless of packages used.