Skip to content

Commit 582def3

Browse files
committed
system.time(); prettyunis
1 parent 14c7926 commit 582def3

File tree

3 files changed

+20
-23
lines changed

3 files changed

+20
-23
lines changed

DESCRIPTION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ Imports:
2828
stats,
2929
tidyr,
3030
globals,
31+
prettyunits,
3132
vctrs (>= 0.2.0)
3233
Roxygen: list(markdown = TRUE)
3334
RoxygenNote: 6.1.99.9001

R/fit.R

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,8 +367,7 @@ check_xy_interface <- function(x, y, cl, model) {
367367
#' @export
368368
print.model_fit <- function(x, ...) {
369369
cat("parsnip model object\n\n")
370-
cat("Fit in: ", paste(format(unclass(x$elapsed), digits = 2),
371-
attr(x$elapsed, "units")))
370+
cat("Fit in: ", prettyunits::pretty_sec(x$elapsed[["elapsed"]]))
372371

373372
if (inherits(x$fit, "try-error")) {
374373
cat("Model fit failed with error:\n", x$fit, "\n")

R/fit_helpers.R

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,17 @@ form_form <-
5252
spec = object
5353
)
5454

55-
start <- Sys.time()
56-
57-
res$fit <- eval_mod(
58-
fit_call,
59-
capture = control$verbosity == 0,
60-
catch = control$catch,
61-
env = env,
62-
...
55+
elapsed <- system.time(
56+
res$fit <- eval_mod(
57+
fit_call,
58+
capture = control$verbosity == 0,
59+
catch = control$catch,
60+
env = env,
61+
...
62+
)
6363
)
64-
65-
end <- Sys.time()
6664
res$preproc <- list(y_var = all.vars(env$formula[[2]]))
67-
res$elapsed <- end - start
65+
res$elapsed <- elapsed
6866
res
6967
}
7068

@@ -112,25 +110,24 @@ xy_xy <- function(object, env, control, target = "none", ...) {
112110

113111
res <- list(lvl = levels(env$y), spec = object)
114112

115-
start <- Sys.time()
116113

117-
res$fit <- eval_mod(
118-
fit_call,
119-
capture = control$verbosity == 0,
120-
catch = control$catch,
121-
env = env,
122-
...
114+
elapsed <- system.time(
115+
res$fit <- eval_mod(
116+
fit_call,
117+
capture = control$verbosity == 0,
118+
catch = control$catch,
119+
env = env,
120+
...
121+
)
123122
)
124123

125-
end <- Sys.time()
126-
127124
if (is.vector(env$y)) {
128125
y_name <- character(0)
129126
} else {
130127
y_name <- colnames(env$y)
131128
}
132129
res$preproc <- list(y_var = y_name)
133-
res$elapsed <- end - start
130+
res$elapsed <- elapsed
134131
res
135132
}
136133

0 commit comments

Comments
 (0)