Skip to content

Commit f0d8106

Browse files
committed
fixed varying search
1 parent f8ef8c3 commit f0d8106

File tree

3 files changed

+44
-51
lines changed

3 files changed

+44
-51
lines changed

R/varying.R

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,23 @@ varying <- function()
1919
#' library(dplyr)
2020
#' library(rlang)
2121
#'
22-
#' #rand_forest() %>% varying_args(id = "plain")
22+
#' rand_forest() %>% varying_args(id = "plain")
2323
#'
24-
#' #rand_forest(mtry = varying()) %>% varying_args(id = "one arg")
24+
#' rand_forest(mtry = varying()) %>% varying_args(id = "one arg")
2525
#'
26-
#' #rand_forest(others = list(sample.fraction = varying())) %>%
27-
#' # varying_args(id = "only others")
26+
#' rand_forest(others = list(sample.fraction = varying())) %>%
27+
#' varying_args(id = "only others")
2828
#'
29-
#' #rand_forest(
30-
#' # others = list(
31-
#' # strata = expr(Class),
32-
#' # sampsize = c(varying(), varying())
33-
#' # )
34-
#' #) %>%
35-
#' # varying_args(id = "add an expr")
29+
#' rand_forest(
30+
#' others = list(
31+
#' strata = expr(Class),
32+
#' sampsize = c(varying(), varying())
33+
#' )
34+
#' ) %>%
35+
#' varying_args(id = "add an expr")
3636
#'
37-
#' # rand_forest(others = list(classwt = c(class1 = 1, class2 = varying()))) %>%
38-
#' # varying_args(id = "list of values")
37+
#' rand_forest(others = list(classwt = c(class1 = 1, class2 = varying()))) %>%
38+
#' varying_args(id = "list of values")
3939
#'
4040
#' @export
4141
varying_args <- function (x, id, ...)
@@ -113,6 +113,7 @@ varying_args.step <- function(x, id = NULL, ...) {
113113
x <- x[!(names(x) %in% exclude)]
114114
x <- x[!map_lgl(x, is.null)]
115115
res <- map(x, find_varying)
116+
116117
res <- map_lgl(res, any)
117118
tibble(
118119
name = names(res),
@@ -138,16 +139,18 @@ is_varying <- function(x) {
138139

139140
# Error: C stack usage 7970880 is too close to the limit (in some cases)
140141
find_varying <- function(x) {
141-
if (is.atomic(x) | is.name(x)) {
142+
if (is_quosure(x))
143+
x <- quo_get_expr(x)
144+
if (is_varying(x)) {
145+
return(TRUE)
146+
} else if (is.atomic(x) | is.name(x)) {
142147
FALSE
143-
} else if (is.call(x)) {
144-
if (is_varying(x)) {
145-
TRUE
146-
} else {
147-
find_varying(x)
148+
} else if (is.call(x) || is.pairlist(x)) {
149+
for (i in seq_along(x)) {
150+
if (is_varying(x[[i]]))
151+
return(TRUE)
148152
}
149-
} else if (is.pairlist(x)) {
150-
find_varying(x)
153+
FALSE
151154
} else if (is.vector(x) | is.list(x)) {
152155
map_lgl(x, find_varying)
153156
} else {

man/varying_args.Rd

Lines changed: 13 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test_varying.R

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ context("varying parameters")
88
load("recipes_examples.RData")
99

1010
test_that('main parsnip arguments', {
11-
skip("Fixes are required")
11+
1212
mod_1 <-
1313
rand_forest() %>%
1414
varying_args(id = "")
@@ -39,9 +39,9 @@ test_that('main parsnip arguments', {
3939

4040

4141
test_that('other parsnip arguments', {
42-
skip("Fixes are required")
42+
4343
other_1 <-
44-
rand_forest(others = list(sample.fraction = varying())) %>%
44+
rand_forest(sample.fraction = varying()) %>%
4545
varying_args(id = "only others")
4646
exp_1 <-
4747
tibble(
@@ -53,7 +53,7 @@ test_that('other parsnip arguments', {
5353
expect_equal(other_1, exp_1)
5454

5555
other_2 <-
56-
rand_forest(min_n = varying(), others = list(sample.fraction = varying())) %>%
56+
rand_forest(min_n = varying(), sample.fraction = varying()) %>%
5757
varying_args(id = "only others")
5858
exp_2 <-
5959
tibble(
@@ -65,12 +65,7 @@ test_that('other parsnip arguments', {
6565
expect_equal(other_2, exp_2)
6666

6767
other_3 <-
68-
rand_forest(
69-
others = list(
70-
strata = expr(Class),
71-
sampsize = c(varying(), varying())
72-
)
73-
) %>%
68+
rand_forest(strata = Class, sampsize = c(varying(), varying())) %>%
7469
varying_args(id = "add an expr")
7570
exp_3 <-
7671
tibble(
@@ -82,12 +77,7 @@ test_that('other parsnip arguments', {
8277
expect_equal(other_3, exp_3)
8378

8479
other_4 <-
85-
rand_forest(
86-
others = list(
87-
strata = expr(Class),
88-
sampsize = c(12, varying())
89-
)
90-
) %>%
80+
rand_forest(strata = Class, sampsize = c(12, varying())) %>%
9181
varying_args(id = "num and varying in vec")
9282
exp_4 <-
9383
tibble(
@@ -101,7 +91,7 @@ test_that('other parsnip arguments', {
10191

10292

10393
test_that('recipe parameters', {
104-
skip("Fixes are required")
94+
10595
rec_res_1 <- varying_args(rec_1)
10696
exp_1 <-
10797
tibble(

0 commit comments

Comments
 (0)