← Back to R Course | Chapter 5: Functions | Lesson 7 of 7

Variadic Functions (...) क्या हैं

dots parameter एक function को किसी भी संख्या में extra inputs accept करने देता है, एक bag की तरह जो जितनी groceries आप लाएँ hold कर सकता है। यह इन्हें दूसरे functions को pass करता है।

In this page:

  1. Variadic Functions (...)
Syntax
r
function_name <- function(...) {
  args <- list(...)
  # body using args
}

Variadic Functions (...)

Special ... parameter एक function को किसी भी संख्या में additional arguments accept करने देता है, जिन्हें किसी दूसरे function को forward किया जा सकता है या list(...) से एक list में collect किया जा सकता है।

cat() और paste() जैसे कई built-in functions inputs की एक flexible संख्या accept करने के लिए ... पर depend करते हैं। यह variable-length argument lists के लिए R का mechanism है।

Note: जो extra arguments pass हुए उन्हें inspect या iterate करने के लिए एक function body के अंदर list(...) इस्तेमाल करें।

उदाहरण: Variadic Functions (...)

markup
sum_all <- function(...) {
  values <- c(...)
  sum(values)
}

cat(sum_all(1, 2, 3), "\n")
cat(sum_all(10, 20, 30, 40), "\n")
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. ... को एक normal variable की तरह पढ़ने की कोशिश करना, जैसे length(...), list(...) या c(...) की बजाय।
  2. ... में named arguments pass करना और c(...) इस्तेमाल करते वक्त names खोना।
  3. ... के बाद parameters रखना, जहाँ वे सिर्फ इनके full name से match हो सकते हैं।
चैप्टर सारांश
  • Functions arguments, default arguments, और return values के साथ defined होते हैं।
  • Scope determine करता है कि variables कहाँ visible हैं।
  • Anonymous functions और variadic functions (...) functions को flexible बनाते हैं।
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.