@@ -133,6 +133,10 @@ as_coverage <- function(counters = NULL, ...) {
133133# ' @param code expressions to run.
134134# ' @param env environment the function is defined in.
135135# ' @param enc the enclosing environment which to run the expressions.
136+ # ' @examples
137+ # ' add <- function(x, y) { x + y }
138+ # ' function_coverage(fun = add, code = NULL) # 0% coverage
139+ # ' function_coverage(fun = add, code = add(1, 2) == 3) # 100% coverage
136140# ' @export
137141function_coverage <- function (fun , code = NULL , env = NULL , enc = parent.frame()) {
138142 if (is.function(fun )) {
@@ -175,6 +179,12 @@ function_coverage <- function(fun, code = NULL, env = NULL, enc = parent.frame()
175179# ' functions
176180# ' @param parent_env The parent environment to use when sourcing the files.
177181# ' @inheritParams package_coverage
182+ # ' @examples
183+ # ' # For the purpose of this example, save code containing code and tests to files
184+ # ' cat("add <- function(x, y) { x + y }", file="add.R")
185+ # ' cat("add(1, 2) == 3", file="add_test.R")
186+ # ' # Use file_coverage() to calculate test coverage
187+ # ' file_coverage(source_files = "add.R", test_files = "add_test.R")
178188# ' @export
179189file_coverage <- function (
180190 source_files ,
@@ -218,6 +228,10 @@ file_coverage <- function(
218228# ' @param test_code A character vector of test code
219229# ' @inheritParams file_coverage
220230# ' @param ... Additional arguments passed to [file_coverage()]
231+ # ' @examples
232+ # ' source <- "add <- function(x, y) { x + y }"
233+ # ' test <- "add(1, 2) == 3"
234+ # ' code_coverage(source, test)
221235# ' @export
222236code_coverage <- function (
223237 source_code ,
0 commit comments