Skip to content

Commit 2af7b02

Browse files
committed
add body_append()
1 parent fd532ef commit 2af7b02

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

R/utils.R

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,17 @@
55
#' @importFrom utils packageName
66
pkg_nm <- function() packageName(topenv(environment()))
77

8+
#' @param ans Whether to assign the final results into the 'ans' variable.
9+
#' @noRd
10+
body_append <- function(fn, ..., ans = TRUE) {
11+
args <- rlang::fn_fmls(fn)
12+
body <- rlang::fn_body(fn)
13+
body <- as.list(body)
14+
if (ans) body[[length(body)]] <- rlang::expr(ans <- !!body[[length(body)]])
15+
body <- as.call(c(body, rlang::enexprs(...)))
16+
rlang::new_function(args, body)
17+
}
18+
819
#' Read Example Data
920
#'
1021
#' This function reads example data from the file. If no file is specified, it

0 commit comments

Comments
 (0)