unused argument

My code looks something like this:
f1 <- function (a,b,c){
if (b==0){
result <- some computing involving (a,b)
} else {
result <-some computing involving (a,b,c)

For the cases in which b==0, I don't need c paramether and this gives me unused argument error. How should I deal with it? Thank you all


To help us help you, could you please prepare a reproducible example (reprex) illustrating your issue? Please have a look at this guide, to see how to create one:

A) what andresrcs said :slightly_smiling_face: . I.e more details are necessary.

B) still, some general advice about this kind of problem:

  1. Check that this is an error and not a warning. RStudio does some time warn about that when it shouldn’t , even though it’s worth to check very carefully that this is indeed the case — if that’s a warning

  2. One trick to check that is to use the (cool) replace/rename in scope feature. You basically put the cursor on a variable and click on that menu item, and it lets you rename the variable and it’s name is updated in the scope that it is defined. If it updated in some places but not in others, then you have a real problem of an ”hidden” argument, i.e there is somewhere in the code that an argument with that name is used and it overrides the name of the variable at the external scope.

Try to initialize the function argument before the if if statement and see if changing its name changes the name of the variable in the if statement and that in the function argument list.

That’s what comes to mind at least until you send additional details.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.