Skip to content

Commit

Permalink
minor improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
qddyy committed Oct 23, 2024
1 parent 154a9ab commit 3dcd352
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
17 changes: 8 additions & 9 deletions R/pmt.R
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ pmts <- function(
#' @details The test statistic in `define_pmt` can be defined using either `R` or `Rcpp`, with the `statistic` parameter specified as:
#'
#' - `R`: a function returning a closure that returns a double.
#' - `Rcpp`: a character string defining a captureless lambda (introduced in C++11) returning another lambda that may capture by value, accepts parameters of the same type as const references, and returns a double.
#' - `Rcpp`: a character string defining a captureless lambda (introduced in C++11) returning another lambda, which captures by value, accepts parameters of the same type as const references, and returns a double.
#'
#' When using `Rcpp`, the parameters for different `inherit` are listed as follows. Note that the parameter names are illustrative and may be modified.
#'
Expand All @@ -133,10 +133,10 @@ pmts <- function(
#' rcpp <- define_pmt(
#' inherit = "twosample", rejection = "lr", n_permu = 1e5,
#' statistic = "[](NumericVector x, NumericVector y) {
#' R_len_t n_x = x.size();
#' R_len_t n_y = y.size();
#' return [n_x, n_y](const NumericVector& x, const NumericVector& y) -> double {
#' return sum(x) / n_x - sum(y) / n_y;
#' R_len_t m = x.size();
#' R_len_t n = y.size();
#' return [=](const NumericVector& x, const NumericVector& y) -> double {
#' return sum(x) / m - sum(y) / n;
#' };
#' }"
#' )
Expand Down Expand Up @@ -212,11 +212,10 @@ define_pmt <- function(
", double n_permu, bool progress){",
"auto statistic = ", statistic, ";",
"return progress ?", paste0(
impl, "<PermuBar",
c("Show", "Hide"), ">(",
impl, "<PermuBar", c("Show", "Hide"), ">(",
paste0(
"clone(", args[-n], ")", collapse = ", "
), ", statistic, n_permu)", collapse = " : "
"clone(", args[-n], ")", collapse = ","
), ", statistic, n_permu )", collapse = ":"
), ";}"
)
}
Expand Down
3 changes: 2 additions & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ do_call <- function(func, default = NULL, fixed = NULL, ...) {
env_args <- list2env(list(...), envir = env_args)
env_args <- list2env(as.list(fixed), envir = env_args)

args <- names(env_args)
eval(
as.call(c(func, sapply(names(env_args), as.name, simplify = FALSE))),
as.call(c(func, lapply(`names<-`(args, args), as.name))),
envir = env_args, enclos = parent.frame()
)
}
Expand Down
10 changes: 5 additions & 5 deletions man/pmt.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3dcd352

Please sign in to comment.