We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
as_test
1 parent 275a2d8 commit 7610d42Copy full SHA for 7610d42
1 file changed
R/as_test.R
@@ -0,0 +1,31 @@
1
+as_test <- function(class) {
2
+ init_formals <- formals(class$public_methods$initialize)
3
+
4
+ class_ <- R6Class(
5
+ classname = paste0(class$classname, "_"),
6
+ inherit = class,
7
+ cloneable = FALSE,
8
+ public = list(
9
+ initialize = as.function.default(c(
10
+ alist(args = ), init_formals,
11
+ quote({
12
+ init <- if (is.null(names(args))) {
13
+ rep.int(FALSE, length(args))
14
+ } else {
15
+ names(args) %in% names(init_formals)
16
+ }
17
18
+ do.call(super$initialize, args[init])
19
+ do.call(super$test, args[!init])
20
+ })
21
+ )),
22
23
+ test = NULL
24
+ )
25
26
27
+ as.function.default(c(
28
+ alist(... = ), init_formals,
29
+ quote(class_$new(args = as.list.default(match.call())[-1]))
30
+ ))
31
+}
0 commit comments