Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
251 views
in Technique[技术] by (71.8m points)

I am trying to obtain the lenght of all the formals in r functions in order to know which.max in the list created. I am a Psychologist not a programer

This is the code for creating the list:

objs <- mget(ls("package:base"), inherits = TRUE)
funs <- Filter(is.function, objs)

I have tried this:

form_list <- for(i in names(funs)) {
        formals(i)
}

It produces an empty object. Then I have tried

form_list <- sapply(names(funs), formals)
longer_args <- sapply(form_list, length)
longest_args <- which.max(longer_args)
long_funct <- funs[961]

evaluates:

$scan
funs_elem <- length(formals(scan))

 funs_elem
[1] 22

It is there a shorter way to the answer? Excuse my English.

question from:https://stackoverflow.com/questions/65932782/i-am-trying-to-obtain-the-lenght-of-all-the-formals-in-r-functions-in-order-to-k

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...