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