Variadic Functions (...) क्या हैं
dots parameter एक function को किसी भी संख्या में extra inputs accept करने देता है, एक bag की तरह जो जितनी groceries आप लाएँ hold कर सकता है। यह इन्हें दूसरे functions को pass करता है।
In this page:
Syntax
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 (...)
sum_all <- function(...) {
values <- c(...)
sum(values)
}
cat(sum_all(1, 2, 3), "\n")
cat(sum_all(10, 20, 30, 40), "\n")
Login to try C/C++/Java/PHP code in the editor
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. #}
आम गलतियां
...को एक normal variable की तरह पढ़ने की कोशिश करना, जैसेlength(...),list(...)याc(...)की बजाय।...में named arguments pass करना औरc(...)इस्तेमाल करते वक्त names खोना।...के बाद 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: