How to Handle Error in R: Unused Argument in Function (2 Examples)

This tutorial explains how to deal with the error “unused argument” in the R programming language.

Example 1: Replicate the Error: Unused Argument

fn1 <- function(x) {             # Manually create function
  out <- x * 5
  out
}
fn1(x = 3, y = 7)                # Using own function
# Error in fn1(x = 1, y = 2) : unused argument (y = 2)

Example 2: Solve the Error: Unused Argument

fn2 <- function(x, ...) {        # Manually create function
  out <- x * 5
  out
}
fn2(x = 3, y = 7)                # Using own function
# 15

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed

Menu
Top