Skip to content

Function calls with trailing braced expressions #241

@DavisVaughan

Description

@DavisVaughan

Function calls where a braced expression is present in the last argument deserves a call out, as it is a special function call style (i.e. not exactly flat or expanded)

map(xs, function(x) {
  do_something(x)
})

map(xs, \(x) {
  do_something(x)
})

test_that("description", {
  test_me
})

These make for particularly unique function call layouts, because normally the expansion of the braced expression over multiple lines would force the expansion of every argument in the function call, looking like:

map(
  xs, 
  function(x) {
    do_something(x)
  }
)

map(
  xs, 
  \(x) {
    do_something(x)
  }
)

test_that(
  "description", 
  {
    test_me
  }
)

Note that this only applies to trailing braced expressions, for example with tryCatch() we do full expansion of every argument

tryCatch(
  {
    expr
  },
  error = function(e) {}
)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions