Skip to content

Commit dff211b

Browse files
authored
speed up tune_tbl() helper (#929)
1 parent 787f945 commit dff211b

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

R/tune_args.R

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@ tune_args.model_spec <- function(object, full = FALSE, ...) {
1818
res <- c(arg_id, eng_arg_id)
1919
res <- ifelse(res == "", names(res), res)
2020

21+
len_res <- length(res)
22+
2123
tune_tbl(
2224
name = names(res),
2325
tunable = unname(!is.na(res)),
2426
id = res,
25-
source = "model_spec",
26-
component = model_type,
27-
component_id = NA_character_,
27+
source = rep("model_spec", len_res),
28+
component = rep(model_type, len_res),
29+
component_id = rep(NA_character_, len_res),
2830
full = full
2931
)
3032
}
@@ -65,13 +67,16 @@ tune_tbl <- function(name = character(),
6567
".", sep = "", call. = FALSE)
6668
}
6769

68-
vry_tbl <- tibble::tibble(
69-
name = as.character(name),
70-
tunable = as.logical(tunable),
71-
id = as.character(id),
72-
source = as.character(source),
73-
component = as.character(component),
74-
component_id = as.character(component_id)
70+
vry_tbl <- tibble::new_tibble(
71+
list(
72+
name = as.character(name),
73+
tunable = as.logical(tunable),
74+
id = as.character(id),
75+
source = as.character(source),
76+
component = as.character(component),
77+
component_id = as.character(component_id)
78+
),
79+
nrow = length(as.character(name))
7580
)
7681

7782
if (!full) {

0 commit comments

Comments
 (0)