How many arguments to a function from OUTSIDE the function
arguments, r
Solution
A possible approach:
b <- function(x, y) {}
length(formals(b))
# [1] 2
Problem
In R, how can I determine the number of arguments a function expects? ``` fa = function(x){} fb = function(x,y){} fc = function(x,y,z){} ``` So I want to define a function, `f`, where: ``` f(fa) = 1 f(fb) = 2 f(fc) = 3 ``` and so forth... Basically, I would like the utility of `nargs()` but from outside the function in question. The reason for the above, is that I need to know the number of arguments that a function expects, for a specific implementation of `optim(...)`, where the function being optimised is determined and generated at runtime.