In R, is it possible to define a function using `function`?

Viewed 115

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.

0 Answers
Related