Skip to content

Commit e03bf4d

Browse files
committed
Solved issue of passing arguments to ...
1 parent a5e7d35 commit e03bf4d

File tree

1 file changed

+22
-37
lines changed

1 file changed

+22
-37
lines changed

R/arguments.R

Lines changed: 22 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,29 @@ sub_arg_values <- function (expr, args, ignore = NULL) {
2727

2828
dot_ind <- dot_index(expr)
2929

30-
missing_args <- arg_names[!(arg_names %in% expr_names)]
31-
30+
missing_arg_names <- arg_names[!(arg_names %in% expr_names)]
31+
3232
# If any args not in expression list, see if there are ellipses
3333
# to put them into
34-
if (length(missing_args) > 0) {
34+
if (length(missing_arg_names) > 0) {
3535
if (dot_ind == 0) {
36-
stop("Argument(s) not valid for `",
37-
expr[[1]], "`: ",
38-
paste0(missing_args, collapse = ", "),
39-
call. = FALSE)
40-
} else {
41-
expr[[dot_ind]] <- NULL
36+
stop(
37+
"Argument(s) not valid for `",
38+
expr[[1]],
39+
"`: ",
40+
paste0(missing_arg_names, collapse = ", "),
41+
call. = FALSE
42+
)
4243
}
43-
}
44+
# Add args for ellipses at end of expression
45+
for(i in missing_arg_names) {
46+
expr[[i]] <- args[[i]]
47+
args[[i]] <- NULL
48+
}
49+
}
4450

4551
arg_names <- names(args)
4652

47-
# This doesn't work when arguments have no defaults (e.g. strata)
48-
4953
# Replace argument values with user-specified values which could be
5054
# evaluated objects (i.e. constants like `TRUE`, `200`, etc), quosures, or calls.
5155

@@ -65,35 +69,16 @@ sub_arg_values <- function (expr, args, ignore = NULL) {
6569
}
6670
}
6771
}
68-
69-
# # remove dots if they are in call
70-
# if(rm_ellipses) {
71-
# dot_ind <- dot_index(expr)
72-
# if(dot_ind != 0)
73-
# expr[[dot_ind]] <- NULL
74-
# }
72+
7573
expr
7674
}
7775

78-
76+
## assumes that ellipses have a value such as
77+
## `... = missing_arg()``
7978
dot_index <- function(x) {
80-
# There must be a better way
81-
is_dots <- rep(na_lgl, length(x))
82-
for(i in seq_along(x))
83-
is_dots[i] <- is_dots(x[[i]])
84-
dot_ind <- if (any(is_dots))
85-
which(is_dots)
86-
else
87-
0
88-
dot_ind
89-
}
90-
91-
is_dots <- function(x) {
92-
if(!inherits(x, "name")) {
93-
res <- FALSE
94-
} else {
95-
res <- isTRUE(all.equal(x, quote(...)))
96-
}
79+
res <- which(names(x) == "...")
80+
if(length(res) == 0)
81+
res <- 0
9782
res
9883
}
9984

0 commit comments

Comments
 (0)