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

Create function internal_make_spec_tbl() #77

Closed
2 tasks done
spsanderson opened this issue Jan 4, 2023 · 0 comments · Fixed by #81
Closed
2 tasks done

Create function internal_make_spec_tbl() #77

spsanderson opened this issue Jan 4, 2023 · 0 comments · Fixed by #81
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@spsanderson
Copy link
Owner

spsanderson commented Jan 4, 2023

Function:

internal_make_spec_tbl <- function(.data){
  
  # Checks ----
  df <- dplyr::as_tibble(.data)
  
  nms <- unique(names(df))
  
  if (!".parsnip_engine" %in% nms | !".parsnip_mode" %in% nms | !".parsnip_fns" %in% nms){
    rlang::abort(
      message = "The model tibble must come from the class/reg to parsnip function.",
      use_cli_format = TRUE
    )
  }
  
  # Make tibble ----
  mod_spec_tbl <- df %>%
    dplyr::mutate(
      model_spec = purrr::pmap(
        dplyr::cur_data(),
        ~ match.fun(..3)(mode = ..2, engine = ..1)
      )
    ) %>%
    # add .model_id column
    dplyr::mutate(.model_id = dplyr::row_number()) %>%
    dplyr::select(.model_id, dplyr::everything())
  
  # Return ----
  return(mod_spec_tbl)
  
}

Example:

> internal_make_spec_tbl(mod_tbl)
# A tibble: 46 × 5
   .model_id .parsnip_engine .parsnip_mode .parsnip_fns model_spec
       <int> <chr>           <chr>         <chr>        <list>    
 1         1 lm              regression    linear_reg   <spec[+]> 
 2         2 brulee          regression    linear_reg   <spec[+]> 
 3         3 gee             regression    linear_reg   <spec[+]> 
 4         4 glm             regression    linear_reg   <spec[+]> 
 5         5 glmer           regression    linear_reg   <spec[+]> 
 6         6 glmnet          regression    linear_reg   <spec[+]> 
 7         7 gls             regression    linear_reg   <spec[+]> 
 8         8 lme             regression    linear_reg   <spec[+]> 
 9         9 lmer            regression    linear_reg   <spec[+]> 
10        10 stan            regression    linear_reg   <spec[+]> 
# … with 36 more rows
# ℹ Use `print(n = ...)` to see more rows
@spsanderson spsanderson added the enhancement New feature or request label Jan 4, 2023
@spsanderson spsanderson added this to the tidyAML 0.0.1 milestone Jan 4, 2023
@spsanderson spsanderson self-assigned this Jan 4, 2023
spsanderson added a commit that referenced this issue Jan 4, 2023
Fixes #77
Fixes #79
Fixes #80
@spsanderson spsanderson mentioned this issue Jan 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

Successfully merging a pull request may close this issue.

1 participant