Skip to content

Commit ea6ec0d

Browse files
committed
two-column approach (probably won't be used)
1 parent ab1a405 commit ea6ec0d

File tree

5 files changed

+56
-31
lines changed

5 files changed

+56
-31
lines changed

NAMESPACE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ export(new_model_spec)
145145
export(null_model)
146146
export(null_value)
147147
export(nullmodel)
148+
export(parsnip_addin)
148149
export(pred_value_template)
149150
export(predict.model_fit)
150151
export(predict_class.model_fit)
@@ -189,7 +190,6 @@ export(update_engine_parameters)
189190
export(update_main_parameters)
190191
export(varying)
191192
export(varying_args)
192-
export(write_parsnip_specs)
193193
export(xgb_train)
194194
importFrom(dplyr,arrange)
195195
importFrom(dplyr,as_tibble)

NEWS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# parsnip (development version)
22

3-
* An RStudio add-in is availble that makes writing multiple `parsnip` model specifications to the source window. It can be accessed via the IDE addin menus or by calling `write_parsnip_specs()`.
3+
* An RStudio add-in is availble that makes writing multiple `parsnip` model specifications to the source window. It can be accessed via the IDE addin menus or by calling `parsnip_addin()`.
44

55
# parsnip 0.1.4
66

R/add_in.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#' Start an RStudio Addin that can write model specifications
22
#'
3-
#' `write_parsnip_specs()` starts a process in the RStudio IDE Viewer window
3+
#' `parsnip_addin()` starts a process in the RStudio IDE Viewer window
44
#' that allows users to write code for `parsnip` model specifications from
55
#' various R packages. The new code is written to the current document at the
66
#' location of the cursor.
77
#'
88
#' @export
9-
write_parsnip_specs <- function() {
9+
parsnip_addin <- function() {
1010
sys.source(
1111
system.file("add-in", "gadget.R", package = "parsnip", mustWork = TRUE),
1212
envir = rlang::new_environment(parent = rlang::global_env()),

inst/add-in/gadget.R

Lines changed: 47 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -64,22 +64,28 @@ parsnip_spec_add_in <- function() {
6464
miniPage(
6565
gadgetTitleBar("Write out model specifications"),
6666
miniContentPanel(
67-
radioButtons(
68-
"model_mode",
69-
label = h3("Type of Model"),
70-
choices = c("Classification", "Regression")
71-
),
72-
checkboxInput(
73-
"tune_args",
74-
label = "Tag parameters for tuning (if any)?",
75-
value = TRUE
76-
),
77-
textInput(
78-
"pattern",
79-
label = "Match on (regex)"
80-
),
81-
tags$br(),
82-
uiOutput("model_choices")
67+
fillRow(
68+
fillCol(
69+
radioButtons(
70+
"model_mode",
71+
label = h3("Type of Model"),
72+
choices = c("Classification", "Regression")
73+
),
74+
checkboxInput(
75+
"tune_args",
76+
label = "Tag parameters for tuning (if any)?",
77+
value = TRUE
78+
),
79+
textInput(
80+
"pattern",
81+
label = "Match on (regex)"
82+
)
83+
),
84+
fillRow(
85+
miniContentPanel(uiOutput("model_choices_left")),
86+
miniContentPanel(uiOutput("model_choices_right"))
87+
)
88+
)
8389
),
8490
miniButtonBlock(
8591
actionButton("write", "Write specification code", class = "btn-success")
@@ -101,19 +107,37 @@ parsnip_spec_add_in <- function() {
101107
models
102108
}) # get_models
103109

104-
output$model_choices <- renderUI({
110+
output$model_choices_left <- renderUI({
105111

106112
model_list <- get_models()
107113

108114
choices <- paste0(model_list$model, " (", model_list$engine, ")")
115+
choices <- unique(choices)
116+
# ind <- ceiling(length(choices)/2)
117+
# choices <- choices[1:ind]
109118

110119
checkboxGroupInput(
111-
inputId = "model_name",
112-
label = "Model",
113-
choices = c(unique(choices))
120+
inputId = "model_name_left",
121+
label = "",
122+
choices = choices
114123
)
115-
}) # model_choices
124+
}) # model_choices_right
125+
126+
output$model_choices_right <- renderUI({
127+
128+
model_list <- get_models()
116129

130+
choices <- paste0(model_list$model, " (", model_list$engine, ")")
131+
choices <- unique(choices)
132+
ind <- ceiling(length(choices)/2) + 1
133+
choices <- choices[ind:length(choices)]
134+
135+
checkboxGroupInput(
136+
inputId = "model_name_right",
137+
label = "",
138+
choices = choices
139+
)
140+
}) # model_choices_right
117141

118142
create_code <- reactive({
119143

@@ -124,7 +148,8 @@ parsnip_spec_add_in <- function() {
124148
selected <- model_db[model_db$label %in% input$model_name,]
125149
selected <- selected[selected$mode %in% model_mode,]
126150

127-
res <- purrr::map_chr(1:nrow(selected), ~ make_spec(selected[.x,], tune_args = input$tune_args))
151+
res <- purrr::map_chr(1:nrow(selected),
152+
~ make_spec(selected[.x,], tune_args = input$tune_args))
128153

129154
paste0(res, sep = "\n\n")
130155

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)