Skip to content

Commit

Permalink
Merge pull request #8 from krlmlr/b-7-missing
Browse files Browse the repository at this point in the history
expand_function() supports code with missing arguments
  • Loading branch information
dirkschumacher authored Feb 6, 2020
2 parents c5a3c62 + cc01c38 commit feac559
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion R/macro.R
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ expand_code <- function(code, macro_environment) {
on_element <- function(push, inplace_update_ast, element) {
path <- element$path
ast <- element$ast
if (!is.call(ast)) {
if (missing(ast) || !is.call(ast)) {
return()
}
fun_name <- paste0(deparse(ast[[1L]]), collapse = "")
Expand Down
8 changes: 8 additions & 0 deletions tests/testthat/test-expand.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ test_that("simple expand example works", {
}))
})

test_that("missing arguments are supported", {
fun <- function() {
iris[1, ]
}

expect_identical(expand_function(fun), fun)
})

test_that("expanding a macro retains attributes", {
add <- defmacro(function() {
1
Expand Down

0 comments on commit feac559

Please sign in to comment.