Skip to content

Commit

Permalink
add body_append()
Browse files Browse the repository at this point in the history
  • Loading branch information
Yunuuuu committed Sep 22, 2024
1 parent fd532ef commit 2af7b02
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@
#' @importFrom utils packageName
pkg_nm <- function() packageName(topenv(environment()))

#' @param ans Whether to assign the final results into the 'ans' variable.
#' @noRd
body_append <- function(fn, ..., ans = TRUE) {
args <- rlang::fn_fmls(fn)
body <- rlang::fn_body(fn)
body <- as.list(body)
if (ans) body[[length(body)]] <- rlang::expr(ans <- !!body[[length(body)]])
body <- as.call(c(body, rlang::enexprs(...)))
rlang::new_function(args, body)
}

#' Read Example Data
#'
#' This function reads example data from the file. If no file is specified, it
Expand Down

0 comments on commit 2af7b02

Please sign in to comment.