Skip to content

Commit a4b3b86

Browse files
authored
Merge pull request #12 from topepo/namespace_usage
Namespace usage in model function call + others
2 parents b5cf7d7 + 482ac9b commit a4b3b86

19 files changed

+1671
-1296
lines changed

DESCRIPTION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ VignetteBuilder: knitr
1414
Depends:
1515
R (>= 2.10)
1616
Imports:
17+
dplyr,
1718
rlang (>= 0.1.6.9003),
1819
purrr,
1920
recipes,

NAMESPACE

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,34 @@
11
# Generated by roxygen2: do not edit by hand
22

33
S3method(fit,model_spec)
4+
S3method(print,linear_reg)
45
S3method(print,logistic_reg)
56
S3method(print,rand_forest)
67
S3method(translate,default)
7-
S3method(translate,logistic_reg)
88
S3method(translate,rand_forest)
9+
S3method(update,linear_reg)
910
S3method(update,logistic_reg)
1011
S3method(update,rand_forest)
1112
export(fit)
1213
export(fit_control)
14+
export(linear_reg)
1315
export(logistic_reg)
1416
export(rand_forest)
1517
export(translate)
1618
export(varying)
1719
import(rlang)
20+
importFrom(dplyr,bind_cols)
1821
importFrom(purrr,list_modify)
1922
importFrom(purrr,map_lgl)
2023
importFrom(recipes,all_outcomes)
2124
importFrom(recipes,all_predictors)
2225
importFrom(recipes,juice)
2326
importFrom(recipes,prep)
2427
importFrom(stats,as.formula)
25-
importFrom(stats,binomial)
2628
importFrom(stats,model.frame)
29+
importFrom(stats,model.matrix)
2730
importFrom(stats,model.response)
2831
importFrom(stats,terms)
2932
importFrom(utils,capture.output)
3033
importFrom(utils,getFromNamespace)
31-
importFrom(utils,globalVariables)
3234
importFrom(utils,installed.packages)

R/arguments.R

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,9 @@ varying <- function()
4141

4242
deharmonize <- function(args, key, engine) {
4343
nms <- names(args)
44-
for(i in seq_along(args)) {
45-
names(args)[i] <- key[ nms[i] , engine ]
46-
}
47-
args
44+
orig_names <- key[nms, engine]
45+
names(args) <- orig_names
46+
args[!is.na(orig_names)]
4847
}
4948

5049
parse_engine_options <- function(x) {
@@ -83,35 +82,16 @@ prune_arg_list <- function(x, whitelist = NULL, modified = character(0)) {
8382
x
8483
}
8584

86-
check_others <- function(args, x) {
87-
85+
check_others <- function(args, obj) {
8886
# Make sure that we are not trying to modify an argument that
8987
# is explicitly protected in the method metadata
90-
common_args <- intersect(x$protect, names(args))
88+
common_args <- intersect(obj$protect, names(args))
9189
if (length(common_args) > 0) {
9290
args <- args[!(names(args) %in% common_args)]
9391
common_args <- paste0(common_args, collapse = ", ")
9492
warning("The following arguments cannot be manually modified ",
9593
"and were removed: ",
9694
common_args, call. = FALSE)
9795
}
98-
99-
# If there are not ellipses in function, make sure that the
100-
# args exist in the fit call
101-
if (length(args) > 0 & !x$has_dots) {
102-
o_names <- names(args)
103-
missing_args <- o_names[!(o_names %in% names(x$fit))]
104-
if (length(missing_args) > 0) {
105-
args[o_names %in% missing_args] <- NULL
106-
warning(
107-
"Some argument(s) do not correspond to this function: ",
108-
paste0("`", o_names, "`", collapse = ", "),
109-
call. = FALSE
110-
)
111-
}
112-
}
11396
args
11497
}
115-
116-
117-

R/engines.R

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,26 @@
11

22
get_model_objects <- function (x, engine) {
3-
if (x$mode == "unknown")
4-
stop("Please specify a mode for the model (e.g. regression, classification, etc.) ",
3+
if (x$mode == "unknown")
4+
stop("Please specify a mode for the model (e.g. regression, classification, etc.) ",
55
"so that the model code can be finalized", call. = FALSE)
66
cls <- specifc_model(x)
77
nm <- paste(cls, engine, "constr", sep = "_")
88
res <- try(get(nm), silent = TRUE)
9-
if (inherits(res, "try-error"))
9+
if (inherits(res, "try-error"))
1010
stop("Can't find model object ", nm)
11-
res()
11+
res
12+
}
13+
14+
get_model_fit_info <- function (x, engine) {
15+
if (x$mode == "unknown")
16+
stop("Please specify a mode for the model (e.g. regression, classification, etc.) ",
17+
"so that the model code can be finalized", call. = FALSE)
18+
cls <- specifc_model(x)
19+
nm <- paste(cls, engine, "fit", sep = "_")
20+
res <- try(get(nm), silent = TRUE)
21+
if (inherits(res, "try-error"))
22+
stop("Can't find model object ", nm)
23+
res
1224
}
1325

1426
specifc_model <- function(x) {

0 commit comments

Comments
 (0)