Skip to content

Commit

Permalink
To balance performance and safety, don't base::*
Browse files Browse the repository at this point in the history
  • Loading branch information
egnha committed Apr 17, 2017
1 parent 02ec888 commit dcfdcaf
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions R/firmly.R
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ warning_closure <- function(.fn, .warn) {
force(.warn)

function() {
call <- base::match.call()
encl <- base::parent.env(base::environment())
call <- match.call()
encl <- parent.env(environment())
encl$.warn(call)

base::eval.parent(encl$.fn(call))
eval.parent(encl$.fn(call))
}
}

Expand Down Expand Up @@ -122,27 +122,26 @@ validating_closure <- function(.chks, .sig, .fn, .warn, .error_class) {
promises <- match.fun("promises")

function() {
call <- base::match.call()
encl <- base::parent.env(base::environment())
call <- match.call()
encl <- parent.env(environment())
encl$.warn(call)

parent <- base::parent.frame()
parent <- parent.frame()
env <- encl$promises(call, encl$.sig, parent)
verdict <- base::suppressWarnings(base::lapply(encl$exprs, function(.)
base::tryCatch(base::eval(.$expr, base::`parent.env<-`(env, .$env)),
error = base::identity)
verdict <- suppressWarnings(lapply(encl$exprs, function(.)
tryCatch(eval(.$expr, `parent.env<-`(env, .$env)), error = identity)
))
pass <- base::vapply(verdict, base::isTRUE, base::logical(1))
pass <- vapply(verdict, isTRUE, logical(1))

if (base::all(pass)) {
base::eval(encl$.fn(call), parent)
if (all(pass)) {
eval(encl$.fn(call), parent)
} else {
fail <- !pass
msg_call <- base::sprintf("%s\n", encl$deparse_collapse(call))
msg_call <- sprintf("%s\n", encl$deparse_collapse(call))
msg_error <- encl$enumerate_many(
encl$problems(encl$.chks[fail, ], verdict[fail])
)
base::stop(encl$error(base::paste0(msg_call, msg_error)))
stop(encl$error(paste0(msg_call, msg_error)))
}
}
}
Expand Down

0 comments on commit dcfdcaf

Please sign in to comment.