Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

Is there a way to get a vector with the name of all functions that one could use in R?

I would like to have a call that returns me a vector with the names of all function that I could call in the current R session. Does anybody know how to achieve this?

(I would like to check user entered variables against this vector. We had some unforseen problem with users entering e.g., c as variable names)

UPDATE: I would like to get the function names from all packages currently loaded.

SOLUTION (half way): Based on Joris Meys tip with lsf.str() I came up with the following function that returns a sorted vector with all currently available function names:

getFunctionNames <- function() {
    loaded <- (.packages())
    loaded <- paste("package:", loaded, sep ="")
    return(sort(unlist(lapply(loaded, lsf.str))))
}

Bu,t see also the comments on Joris Meys' post for even better answers.

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

I'd use lsf.str() as a start.

eg : x <- as.character(lsf.str("package:base")) gives you a list of all functions in the base package. You could do add all packages you want to check against. stats and utils come to mind first.

EDIT : Regarding your question about currently loaded packages :

x <- unlist(sapply(search()[-1],function(x)as.character(lsf.str(x)))) see comments

pkgs <- search()
pkgs <- pkgs[grep("package:",pkgs)]
y <- unlist(sapply(pkgs,lsf.str))

does the trick.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...