Skip to content

Commit 91d1296

Browse files
committed
changed mod argument to model
1 parent d6e80c7 commit 91d1296

17 files changed

+307
-307
lines changed

R/aaa_models.R

Lines changed: 69 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ get_model_env <- function() {
5353
#' that there are no conflicts with the underlying model structures used by the
5454
#' package.
5555
#'
56-
#' @param mod A single character string for the model type (e.g.
56+
#' @param model A single character string for the model type (e.g.
5757
#' `"rand_forest"`, etc).
5858
#' @param new A single logical to check to see if the model that you are check
5959
#' has not already been registered.
@@ -64,8 +64,8 @@ get_model_env <- function() {
6464
#' @param arg A single character string for the model argument name.
6565
#' @keywords internal
6666
#' @export
67-
check_mod_val <- function(mod, new = FALSE, existence = FALSE) {
68-
if (is_missing(mod) || length(mod) != 1)
67+
check_mod_val <- function(model, new = FALSE, existence = FALSE) {
68+
if (is_missing(model) || length(model) != 1)
6969
stop("Please supply a character string for a model name (e.g. `'linear_reg'`)",
7070
call. = FALSE)
7171

@@ -74,15 +74,15 @@ check_mod_val <- function(mod, new = FALSE, existence = FALSE) {
7474
}
7575

7676
if (new) {
77-
if (any(current$models == mod)) {
78-
stop("Model `", mod, "` already exists", call. = FALSE)
77+
if (any(current$models == model)) {
78+
stop("Model `", model, "` already exists", call. = FALSE)
7979
}
8080
}
8181

8282
if (existence) {
8383
current <- get_model_env()
84-
if (!any(current$models == mod)) {
85-
stop("Model `", mod, "` has not been registered.", call. = FALSE)
84+
if (!any(current$models == model)) {
85+
stop("Model `", model, "` has not been registered.", call. = FALSE)
8686
}
8787
}
8888

@@ -250,29 +250,29 @@ check_pkg_val <- function(x) {
250250
#' @rdname get_model_env
251251
#' @keywords internal
252252
#' @export
253-
set_new_model <- function(mod) {
254-
check_mod_val(mod, new = TRUE)
253+
set_new_model <- function(model) {
254+
check_mod_val(model, new = TRUE)
255255

256256
current <- get_model_env()
257257

258-
current$models <- c(current$models, mod)
259-
current[[mod]] <- dplyr::tibble(engine = character(0), mode = character(0))
260-
current[[paste0(mod, "_pkgs")]] <- dplyr::tibble(engine = character(0), pkg = list())
261-
current[[paste0(mod, "_modes")]] <- "unknown"
262-
current[[paste0(mod, "_args")]] <-
258+
current$models <- c(current$models, model)
259+
current[[model]] <- dplyr::tibble(engine = character(0), mode = character(0))
260+
current[[paste0(model, "_pkgs")]] <- dplyr::tibble(engine = character(0), pkg = list())
261+
current[[paste0(model, "_modes")]] <- "unknown"
262+
current[[paste0(model, "_args")]] <-
263263
dplyr::tibble(
264264
engine = character(0),
265265
parsnip = character(0),
266266
original = character(0),
267267
func = list()
268268
)
269-
current[[paste0(mod, "_fit")]] <-
269+
current[[paste0(model, "_fit")]] <-
270270
dplyr::tibble(
271271
engine = character(0),
272272
mode = character(0),
273273
value = list()
274274
)
275-
current[[paste0(mod, "_predict")]] <-
275+
current[[paste0(model, "_predict")]] <-
276276
dplyr::tibble(
277277
engine = character(0),
278278
mode = character(0),
@@ -288,17 +288,17 @@ set_new_model <- function(mod) {
288288
#' @rdname get_model_env
289289
#' @keywords internal
290290
#' @export
291-
set_model_mode <- function(mod, mode) {
292-
check_mod_val(mod, existence = TRUE)
291+
set_model_mode <- function(model, mode) {
292+
check_mod_val(model, existence = TRUE)
293293
check_mode_val(mode)
294294

295295
current <- get_model_env()
296296

297297
if (!any(current$modes == mode)) {
298298
current$modes <- unique(c(current$modes, mode))
299299
}
300-
current[[paste0(mod, "_modes")]] <-
301-
unique(c(current[[paste0(mod, "_modes")]], mode))
300+
current[[paste0(model, "_modes")]] <-
301+
unique(c(current[[paste0(model, "_modes")]], mode))
302302

303303
invisible(NULL)
304304
}
@@ -308,21 +308,21 @@ set_model_mode <- function(mod, mode) {
308308
#' @rdname get_model_env
309309
#' @keywords internal
310310
#' @export
311-
set_model_engine <- function(mod, mode, eng) {
312-
check_mod_val(mod, existence = TRUE)
311+
set_model_engine <- function(model, mode, eng) {
312+
check_mod_val(model, existence = TRUE)
313313
check_mode_val(mode)
314314
check_mode_val(eng)
315315

316316
current <- get_model_env()
317317

318318
new_eng <- dplyr::tibble(engine = eng, mode = mode)
319-
old_eng <- current[[mod]]
319+
old_eng <- current[[model]]
320320
engs <-
321321
old_eng %>%
322322
dplyr::bind_rows(new_eng) %>%
323323
dplyr::distinct()
324324

325-
current[[mod]] <- engs
325+
current[[model]] <- engs
326326

327327
invisible(NULL)
328328
}
@@ -333,15 +333,15 @@ set_model_engine <- function(mod, mode, eng) {
333333
#' @rdname get_model_env
334334
#' @keywords internal
335335
#' @export
336-
set_model_arg <- function(mod, eng, val, original, func, submodels) {
337-
check_mod_val(mod, existence = TRUE)
336+
set_model_arg <- function(model, eng, val, original, func, submodels) {
337+
check_mod_val(model, existence = TRUE)
338338
check_arg_val(val)
339339
check_arg_val(original)
340340
check_func_val(func)
341341
check_submodels_val(submodels)
342342

343343
current <- get_model_env()
344-
old_args <- current[[paste0(mod, "_args")]]
344+
old_args <- current[[paste0(model, "_args")]]
345345

346346
new_arg <-
347347
dplyr::tibble(
@@ -361,7 +361,7 @@ set_model_arg <- function(mod, eng, val, original, func, submodels) {
361361

362362
updated <- dplyr::distinct(updated, engine, parsnip, original, submodels)
363363

364-
current[[paste0(mod, "_args")]] <- updated
364+
current[[paste0(model, "_args")]] <- updated
365365

366366
invisible(NULL)
367367
}
@@ -372,13 +372,13 @@ set_model_arg <- function(mod, eng, val, original, func, submodels) {
372372
#' @rdname get_model_env
373373
#' @keywords internal
374374
#' @export
375-
set_dependency <- function(mod, eng, pkg) {
376-
check_mod_val(mod, existence = TRUE)
375+
set_dependency <- function(model, eng, pkg) {
376+
check_mod_val(model, existence = TRUE)
377377
check_pkg_val(pkg)
378378

379379
current <- get_model_env()
380-
model_info <- current[[mod]]
381-
pkg_info <- current[[paste0(mod, "_pkgs")]]
380+
model_info <- current[[model]]
381+
pkg_info <- current[[paste0(model, "_pkgs")]]
382382

383383
has_engine <-
384384
model_info %>%
@@ -387,7 +387,7 @@ set_dependency <- function(mod, eng, pkg) {
387387
nrow()
388388
if (has_engine != 1) {
389389
stop("The engine '", eng, "' has not been registered for model '",
390-
mod, "'. ", call. = FALSE)
390+
model, "'. ", call. = FALSE)
391391
}
392392

393393
existing_pkgs <-
@@ -407,19 +407,19 @@ set_dependency <- function(mod, eng, pkg) {
407407
dplyr::filter(engine != eng) %>%
408408
dplyr::bind_rows(existing_pkgs)
409409
}
410-
current[[paste0(mod, "_pkgs")]] <- pkg_info
410+
current[[paste0(model, "_pkgs")]] <- pkg_info
411411

412412
invisible(NULL)
413413
}
414414

415415
#' @rdname get_model_env
416416
#' @keywords internal
417417
#' @export
418-
get_dependency <- function(mod) {
419-
check_mod_val(mod, existence = TRUE)
420-
pkg_name <- paste0(mod, "_pkgs")
418+
get_dependency <- function(model) {
419+
check_mod_val(model, existence = TRUE)
420+
pkg_name <- paste0(model, "_pkgs")
421421
if (!any(pkg_name != rlang::env_names(get_model_env()))) {
422-
stop("`", mod, "` does not have a dependency list in parsnip.", call. = FALSE)
422+
stop("`", model, "` does not have a dependency list in parsnip.", call. = FALSE)
423423
}
424424
rlang::env_get(get_model_env(), pkg_name)
425425
}
@@ -430,15 +430,15 @@ get_dependency <- function(mod) {
430430
#' @rdname get_model_env
431431
#' @keywords internal
432432
#' @export
433-
set_fit <- function(mod, mode, eng, value) {
434-
check_mod_val(mod, existence = TRUE)
433+
set_fit <- function(model, mode, eng, value) {
434+
check_mod_val(model, existence = TRUE)
435435
check_mode_val(mode)
436436
check_engine_val(eng)
437437
check_fit_info(value)
438438

439439
current <- get_model_env()
440-
model_info <- current[[paste0(mod)]]
441-
old_fits <- current[[paste0(mod, "_fit")]]
440+
model_info <- current[[paste0(model)]]
441+
old_fits <- current[[paste0(model, "_fit")]]
442442

443443
has_engine <-
444444
model_info %>%
@@ -447,7 +447,7 @@ set_fit <- function(mod, mode, eng, value) {
447447
if (has_engine != 1) {
448448
stop("set_fit The combination of engine '", eng, "' and mode '",
449449
mode, "' has not been registered for model '",
450-
mod, "'. ", call. = FALSE)
450+
model, "'. ", call. = FALSE)
451451
}
452452

453453
has_fit <-
@@ -458,7 +458,7 @@ set_fit <- function(mod, mode, eng, value) {
458458
if (has_fit > 0) {
459459
stop("The combination of engine '", eng, "' and mode '",
460460
mode, "' already has a fit component for model '",
461-
mod, "'. ", call. = FALSE)
461+
model, "'. ", call. = FALSE)
462462
}
463463

464464
new_fit <-
@@ -473,19 +473,19 @@ set_fit <- function(mod, mode, eng, value) {
473473
stop("An error occured when adding the new fit module", call. = FALSE)
474474
}
475475

476-
current[[paste0(mod, "_fit")]] <- updated
476+
current[[paste0(model, "_fit")]] <- updated
477477

478478
invisible(NULL)
479479
}
480480

481481
#' @rdname get_model_env
482482
#' @keywords internal
483483
#' @export
484-
get_fit <- function(mod) {
485-
check_mod_val(mod, existence = TRUE)
486-
fit_name <- paste0(mod, "_fit")
484+
get_fit <- function(model) {
485+
check_mod_val(model, existence = TRUE)
486+
fit_name <- paste0(model, "_fit")
487487
if (!any(fit_name != rlang::env_names(get_model_env()))) {
488-
stop("`", mod, "` does not have a `fit` method in parsnip.", call. = FALSE)
488+
stop("`", model, "` does not have a `fit` method in parsnip.", call. = FALSE)
489489
}
490490
rlang::env_get(get_model_env(), fit_name)
491491
}
@@ -495,15 +495,15 @@ get_fit <- function(mod) {
495495
#' @rdname get_model_env
496496
#' @keywords internal
497497
#' @export
498-
set_pred <- function(mod, mode, eng, type, value) {
499-
check_mod_val(mod, existence = TRUE)
498+
set_pred <- function(model, mode, eng, type, value) {
499+
check_mod_val(model, existence = TRUE)
500500
check_mode_val(mode)
501501
check_engine_val(eng)
502502
check_pred_info(value, type)
503503

504504
current <- get_model_env()
505-
model_info <- current[[paste0(mod)]]
506-
old_fits <- current[[paste0(mod, "_predict")]]
505+
model_info <- current[[paste0(model)]]
506+
old_fits <- current[[paste0(model, "_predict")]]
507507

508508
has_engine <-
509509
model_info %>%
@@ -512,7 +512,7 @@ set_pred <- function(mod, mode, eng, type, value) {
512512
if (has_engine != 1) {
513513
stop("The combination of engine '", eng, "' and mode '",
514514
mode, "' has not been registered for model '",
515-
mod, "'. ", call. = FALSE)
515+
model, "'. ", call. = FALSE)
516516
}
517517

518518
has_pred <-
@@ -523,7 +523,7 @@ set_pred <- function(mod, mode, eng, type, value) {
523523
stop("The combination of engine '", eng, "', mode '",
524524
mode, "', and type '", type,
525525
"' already has a prediction component for model '",
526-
mod, "'. ", call. = FALSE)
526+
model, "'. ", call. = FALSE)
527527
}
528528

529529
new_fit <-
@@ -539,23 +539,23 @@ set_pred <- function(mod, mode, eng, type, value) {
539539
stop("An error occured when adding the new fit module", call. = FALSE)
540540
}
541541

542-
current[[paste0(mod, "_predict")]] <- updated
542+
current[[paste0(model, "_predict")]] <- updated
543543

544544
invisible(NULL)
545545
}
546546

547547
#' @rdname get_model_env
548548
#' @keywords internal
549549
#' @export
550-
get_pred_type <- function(mod, type) {
551-
check_mod_val(mod, existence = TRUE)
552-
pred_name <- paste0(mod, "_predict")
550+
get_pred_type <- function(model, type) {
551+
check_mod_val(model, existence = TRUE)
552+
pred_name <- paste0(model, "_predict")
553553
if (!any(pred_name != rlang::env_names(get_model_env()))) {
554-
stop("`", mod, "` does not have any `pred` methods in parsnip.", call. = FALSE)
554+
stop("`", model, "` does not have any `pred` methods in parsnip.", call. = FALSE)
555555
}
556556
all_preds <- rlang::env_get(get_model_env(), pred_name)
557557
if (!any(all_preds$type == type)) {
558-
stop("`", mod, "` does not have any `", type,
558+
stop("`", model, "` does not have any `", type,
559559
"` prediction methods in parsnip.", call. = FALSE)
560560
}
561561
dplyr::filter(all_preds, type == !!type)
@@ -564,7 +564,7 @@ get_pred_type <- function(mod, type) {
564564
# ------------------------------------------------------------------------------
565565

566566
#' @export
567-
validate_model <- function(mod) {
567+
validate_model <- function(model) {
568568
# check for consistency across engines, modes, args, etc
569569
}
570570

@@ -573,19 +573,19 @@ validate_model <- function(mod) {
573573
#' @rdname get_model_env
574574
#' @keywords internal
575575
#' @export
576-
show_model_info <- function(mod) {
577-
check_mod_val(mod, existence = TRUE)
576+
show_model_info <- function(model) {
577+
check_mod_val(model, existence = TRUE)
578578
current <- get_model_env()
579579

580-
cat("Information for `", mod, "`\n", sep = "")
580+
cat("Information for `", model, "`\n", sep = "")
581581

582582
cat(
583583
" modes:",
584-
paste0(current[[paste0(mod, "_modes")]], collapse = ", "),
584+
paste0(current[[paste0(model, "_modes")]], collapse = ", "),
585585
"\n"
586586
)
587587

588-
engines <- current[[paste0(mod)]]
588+
engines <- current[[paste0(model)]]
589589
if (nrow(engines) > 0) {
590590
cat(" engines: \n")
591591
engines %>%
@@ -606,7 +606,7 @@ show_model_info <- function(mod) {
606606
cat(" no registered engines yet.")
607607
}
608608

609-
args <- current[[paste0(mod, "_args")]]
609+
args <- current[[paste0(model, "_args")]]
610610
if (nrow(args) > 0) {
611611
cat(" arguments: \n")
612612
args %>%
@@ -629,7 +629,7 @@ show_model_info <- function(mod) {
629629
cat(" no registered arguments yet.")
630630
}
631631

632-
fits <- current[[paste0(mod, "_fits")]]
632+
fits <- current[[paste0(model, "_fits")]]
633633
if (nrow(fits) > 0) {
634634

635635
} else {

0 commit comments

Comments
 (0)