जैसा कि अजीब ने नोट किया, यह args
प्रिंट चीजों से संबंधित एक विषमता है। यही है, चाहे args
में इसके आउटपुट में बाइटकोड लाइन शामिल है, यह फ़ंक्शन बाइट संकलित किया गया था या नहीं, इस पर एक विश्वसनीय संकेतक नहीं है। तुलना:
args(writeLines)
## function (text, con = stdout(), sep = "\n", useBytes = FALSE)
## NULL
writeLines
## function (text, con = stdout(), sep = "\n", useBytes = FALSE)
## {
## if (is.character(con)) {
## con <- file(con, "w")
## on.exit(close(con))
## }
## .Internal(writeLines(text, con, sep, useBytes))
## }
## <bytecode: 0x000000001bf3aeb0>
हम args
बनाम मानक समारोह मुद्रण एक बाईटकोड लाइन की छपाई की तुलना कर सकते हैं।
arg_shows_bytecode <- function(fn)
{
output <- capture.output(args(fn))
grepl("^<bytecode", output[length(output)])
}
printing_shows_bytecode <- function(fn)
{
output <- capture.output(print(fn))
length(output) > 1 && grepl("^<bytecode", output[length(output) - 1])
}
base_fns <- Filter(is.function, mget(ls(baseenv()), baseenv()))
yn_args <- vapply(base_fns, arg_shows_bytecode, logical(1))
yn_print <- vapply(base_fns, printing_shows_bytecode, logical(1))
यह ध्यान देने योग्य है कि सभी कार्यों जहां args
बाईटकोड जानकारी से पता चलता पुरातन हैं लायक है।
head(base_fns[yn_args])
## $`%*%`
## function (x, y) .Primitive("%*%")
##
## $as.call
## function (x) .Primitive("as.call")
##
## $attr
## function (x, which, exact = FALSE) .Primitive("attr")
##
## $`attr<-`
## function (x, which, value) .Primitive("attr<-")
##
## $attributes
## function (obj) .Primitive("attributes")
##
## $`attributes<-`
## function (obj, value) .Primitive("attributes<-")
बातचीत सच नहीं है: कुछ आधार कार्य जहां args
बाईटकोड जानकारी प्रदर्शित नहीं करता है पुरातन कर रहे हैं; अन्य नहीं हैं। आधार पैकेज में
yn_prim <- vapply(base_fns, is.primitive, logical(1))
table(yn_args, yn_print, yn_prim)
## , , yn_prim = FALSE
##
## yn_print
## yn_args FALSE TRUE
## FALSE 0 988
## TRUE 0 0
##
## , , yn_prim = TRUE
##
## yn_print
## yn_args FALSE TRUE
## FALSE 119 0
## TRUE 63 0
तो गैर आदिम कार्यों सभी संकलित किए जाते हैं, लेकिन args
यह उल्लेख नहीं है। मुद्रित होने पर प्राथमिक कार्य बाइटकोड संदेश नहीं दिखाते हैं, और केवल कभी-कभी तर्क के साथ बुलाए जाने पर बाइटकोड संदेश दिखाते हैं।
मुझे लगता है कि प्रिंटिंग अंतर अधिक ऐतिहासिक कारणों के लिए है। कंसोल प्रिंटिंग के लिए 'args' का अधिक उपयोग किया जाता है, शायद अधिक सुसंगत आउटपुट प्राप्त करने के लिए' फॉर्मल्स 'का उपयोग करें। – agstudy