5

In R, most statements can be written as a function call. For example...

for (ii in 1:10) print(ii) 

can be written as

`for`(ii, 1:10, print(ii))

However, when I try to write a function using this approach...

# normal approach
function (a = 1) 2

# call approach
`function`(pairlist(a = 1), 2)

I get an error: invalid formal argument list for "function". This seems to be referring to the first argument (the pairlist).

Is it possible to define a function directly in this way, without wrapping it in substitute?

A bit of searching turned up this email thread, which suggests 4 approaches, but none call "`function`" directly.

machow
  • 1,034
  • 1
  • 10
  • 16
  • 1
    Apologies, I overlooked this excellent question when asking my own, and only found it afterwards. I would have closed mine as a duplicate of this one rather than the other way round, but the Stack Overflow software wouldn’t let me. – Konrad Rudolph Feb 08 '19 at 18:05
  • No worries--just glad to see some good discussion of the issue the question you posted! – machow Feb 23 '19 at 22:33

0 Answers0