Skip to content

Commit 7bc24ff

Browse files
authored
Merge pull request #68 from topepo/fix/fit-pkg-library-call
Fix) get_method() should be called before the package installation checks
2 parents 2afd4a7 + 5e2ed52 commit 7bc24ff

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

R/engines.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ check_engine <- function(object) {
4141
#' @importFrom utils installed.packages
4242
check_installs <- function(x) {
4343
lib_inst <- rownames(installed.packages())
44-
if (length(x$method$library) > 0) {
45-
is_inst <- x$method$library %in% lib_inst
44+
if (length(x$method$libs) > 0) {
45+
is_inst <- x$method$libs %in% lib_inst
4646
if (any(!is_inst)) {
4747
stop(
4848
"This engine requires some package installs: ",
49-
paste0("'", x$method$library[!is_inst], "'", collapse = ", ")
49+
paste0("'", x$method$libs[!is_inst], "'", collapse = ", ")
5050
)
5151
}
5252
}

R/fit.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,13 @@ fit.model_spec <-
117117
"with a spark data object.", call. = FALSE
118118
)
119119

120+
# populate `method` with the details for this model type
121+
object <- get_method(object, engine = object$engine)
122+
120123
check_installs(object) # TODO rewrite with pkgman
121124
# TODO Should probably just load the namespace
122125
load_libs(object, control$verbosity < 2)
123126

124-
# populate `method` with the details for this model type
125-
object <- get_method(object, engine = object$engine)
126-
127127
interfaces <- paste(fit_interface, object$method$fit$interface, sep = "_")
128128

129129
# Now call the wrappers that transition between the interface

R/misc.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,19 +67,19 @@ model_printer <- function(x, ...) {
6767
if (!is.null(x$method$fit_call)) {
6868
cat("Fit function:\n")
6969
print(x$method$fit_call)
70-
if (length(x$method$library) > 0) {
71-
if (length(x$method$library) > 1)
70+
if (length(x$method$libs) > 0) {
71+
if (length(x$method$libs) > 1)
7272
cat("\nRequired packages:\n")
7373
else
7474
cat("\nRequired package: ")
75-
cat(paste0(x$method$library, collapse = ", "), "\n")
75+
cat(paste0(x$method$libs, collapse = ", "), "\n")
7676
}
7777
}
7878
}
7979
}
8080

8181
load_libs <- function(x, quiet) {
82-
for (pkg in x$method$library)
82+
for (pkg in x$method$libs)
8383
suppressPackageStartupMessages(requireNamespace(pkg, quietly = quiet))
8484
invisible(x)
8585
}

0 commit comments

Comments
 (0)