Skip to content

Commit

Permalink
Labelling for mutli-line functions
Browse files Browse the repository at this point in the history
Fixes #583
  • Loading branch information
hadley committed Oct 1, 2017
1 parent 1e5997f commit f7dd41b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
7 changes: 6 additions & 1 deletion R/expectation.R
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,12 @@ label <- function(x) {
} else {
chr <- deparse(x)
if (length(chr) > 1) {
chr <- paste(deparse(as.call(list(x[[1]], quote(...)))), collapse = "\n")
if (identical(x[[1]], quote(`function`))) {
x[[3]] <- quote(...)
chr <- paste(deparse(x), collapse = "\n")
} else {
chr <- paste(deparse(as.call(list(x[[1]], quote(...)))), collapse = "\n")
}
}
chr
}
Expand Down
6 changes: 6 additions & 0 deletions tests/testthat/test-label.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ test_that("labelling compound {} expression gives single string", {
expect_type(out, "character")
})

test_that("can label multiline functions", {
expect_equal(
label(function(x, y) {}),
"function(x, y) ..."
)
})

test_that("can find label after it's been forced", {
f <- function(x) {
Expand Down

0 comments on commit f7dd41b

Please sign in to comment.