Skip to content

Commit

Permalink
use do.call in .preprocess()
Browse files Browse the repository at this point in the history
  • Loading branch information
qddyy committed Feb 7, 2024
1 parent a06e640 commit f96442e
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 15 deletions.
2 changes: 1 addition & 1 deletion R/ContingencyTableTest.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ ContingencyTableTest <- R6Class(
}

private$.data <- unname(
do_call(cbind, lapply(private$.raw_data, as.integer))
do.call(cbind, lapply(private$.raw_data, as.integer))
)

if (any(private$.data < 0)) {
Expand Down
2 changes: 1 addition & 1 deletion R/RCBDTest.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ RCBDTest <- R6Class(
stop("All samples must be of equal length")
}

private$.data <- unname(do_call(cbind, private$.raw_data))
private$.data <- unname(do.call(cbind, private$.raw_data))
},

.calculate_score = function() {
Expand Down
2 changes: 1 addition & 1 deletion R/TwoSampleAssociationTest.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ TwoSampleAssociationTest <- R6Class(
stop("Both samples must be of equal length")
}

private$.data <- do_call(data.frame, private$.data)
private$.data <- do.call(data.frame, private$.data)
},

.calculate_score = function() {},
Expand Down
2 changes: 1 addition & 1 deletion R/TwoSamplePairedTest.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ TwoSamplePairedTest <- R6Class(
stop("Both samples must be of equal length")
}

private$.data <- do_call(data.frame, private$.data)
private$.data <- do.call(data.frame, private$.data)
},

.calculate_score = function() {},
Expand Down
24 changes: 13 additions & 11 deletions R/utils.R
Original file line number Diff line number Diff line change
@@ -1,14 +1,3 @@
do_call <- function(func, default = NULL, fixed = NULL, ...) {
env_args <- list2env(as.list(default))
env_args <- list2env(list(...), envir = env_args)
env_args <- list2env(as.list(fixed), envir = env_args)

eval(
as.call(c(func, sapply(names(env_args), as.name, simplify = FALSE))),
envir = env_args, enclos = parent.frame()
)
}

# for test()

get_data <- function(call, env) {
Expand Down Expand Up @@ -43,6 +32,19 @@ get_data <- function(call, env) {
), data_names)
}

# for plot()

do_call <- function(func, default = NULL, fixed = NULL, ...) {
env_args <- list2env(as.list(default))
env_args <- list2env(list(...), envir = env_args)
env_args <- list2env(as.list(fixed), envir = env_args)

eval(
as.call(c(func, sapply(names(env_args), as.name, simplify = FALSE))),
envir = env_args, enclos = parent.frame()
)
}

# for .calculate_score()

get_score <- function(x, method, n = length(x)) {
Expand Down

0 comments on commit f96442e

Please sign in to comment.