Skip to content

Commit 9dc2d40

Browse files
committed
Improvements to the descriptor finder
1 parent 61d3a99 commit 9dc2d40

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

R/descriptors.R

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ get_descr_xy <- function(x, y) {
281281
}
282282

283283
.dat <- function() {
284-
convert_xy_to_form_fit(x, y)
284+
convert_xy_to_form_fit(x, y)$data
285285
}
286286

287287
.x <- function() {
@@ -324,9 +324,12 @@ make_descr <- function(object) {
324324

325325
# Locate descriptors -----------------------------------------------------------
326326

327-
# take a list of arguments, see if any require descriptors
328-
requires_descrs <- function(lst) {
329-
any(map_lgl(lst, has_any_descrs))
327+
# take a model spec, see if any require descriptors
328+
requires_descrs <- function(object) {
329+
any(c(
330+
map_lgl(object$args, has_any_descrs),
331+
map_lgl(object$others, has_any_descrs)
332+
))
330333
}
331334

332335
# given a quosure arg, does the expression contain a descriptor function?
@@ -343,7 +346,12 @@ has_any_descrs <- function(x) {
343346

344347
# globals::globalsOf() is recursive and finds globals if the user passes
345348
# in a function that wraps a descriptor fn
346-
.globals <- globals::globalsOf(expr = .x_expr, envir = .x_env)
349+
.globals <- globals::globalsOf(
350+
expr = .x_expr,
351+
envir = .x_env,
352+
mustExist = FALSE
353+
)
354+
347355
.globals <- names(.globals)
348356

349357
any(map_lgl(.globals, is_descr))

R/fit_helpers.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ form_form <-
1616
object <- check_mode(object, y_levels)
1717

1818
# if descriptors are needed, update descr_env with the calculated values
19-
if(requires_descrs(object$args)) {
19+
if(requires_descrs(object)) {
2020
data_stats <- get_descr_form(env$formula, env$data)
2121
scoped_descrs(data_stats)
2222
}
@@ -68,7 +68,7 @@ xy_xy <- function(object, env, control, target = "none", ...) {
6868
object <- check_mode(object, levels(env$y))
6969

7070
# if descriptors are needed, update descr_env with the calculated values
71-
if(requires_descrs(object$args)) {
71+
if(requires_descrs(object)) {
7272
data_stats <- get_descr_form(env$formula, env$data)
7373
scoped_descrs(data_stats)
7474
}

0 commit comments

Comments
 (0)