Home / Programs / Function with three dot ... parameter in R programming language
🚀 Programming Example

Function with three dot ... parameter in R programming language

👁 376 Views
💻 Practical Program
📘 Step Learning
Function with three dot ... parameter in R programming language

💻 Program Code

# function argument as a three dot ...
hello.person <- function(firstName, lastName = "Ansari", ...)
{
  print(sprintf("Hello %s %s", firstName, lastName))
}



# Azmi will ignore because of the ...
hello.person("Rumman", "Ansari", "Azmi")

# Azmi will ignore because of the ...
hello.person("Rumman", extra = "Azmi")

# another way to call
hello.person("Rumman")

hello.person(firstName = "Rumman")

hello.person(firstName = "Ansari", "Azmi")

# this function calling will not work 
# because "firstName" is missing
hello.person(lastName = "Rumman")
                        

🖥 Program Output

> # Azmi will ignore because of the ...
> hello.person("Rumman", "Ansari", "Azmi")
[1] "Hello Rumman Ansari"
> 
> # Azmi will ignore because of the ...
> hello.person("Rumman", extra = "Azmi")
[1] "Hello Rumman Ansari"
> 
> # another way to call
> hello.person("Rumman")
[1] "Hello Rumman Ansari"
> 
> hello.person(firstName = "Rumman")
[1] "Hello Rumman Ansari"
> 
> hello.person(firstName = "Ansari", "Azmi")
[1] "Hello Ansari Azmi"
> 
> # this function calling will not work 
> # because "firstName" is missing
> hello.person(lastName = "Rumman")
 Error in sprintf("Hello %s %s", firstName, lastName) : 
  argument "firstName" is missing, with no default 
                            

📘 Explanation

This three dot is one of the most powerful features in R Programming Language
📚 Learning Subject

Master Programming Through Practical Examples

Improve your coding logic, problem-solving skills and programming confidence by practicing real-world examples with explanations.

🎯 How to learn from this example

First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.

🔥 Practice suggestion

Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.