如何找到具有给定形式参数签名的所有函数(在当前工作环境中可用,所以base
加上加载的包)?
出现这种情况是因为我试图找到一个用来回答这个问题的例子:If function(x) can work, why would we need function()?
答案 0 :(得分:1)
需要的部分:
apropos("^",mode="function")
length(formals(x))==0
lapply( x, get )
感谢@ apropos的@RichieCotton和is.primitive
的@hadley。
allFxnNames <- apropos("^",mode="function")
emptyFormals <- function(x) length(formals(x))==0 && !is.primitive(x)
allFxns <- lapply( allFxnNames, get )
whichEmpty <- sapply(allFxns, emptyFormals)
allFxnNames[whichEmpty]
这会找到所有没有正式参数的非原始函数:
“闹钟”,“closeAllConnections”,“颜色”,“颜色”,“贡献者”, “Cstack_info”,“date”,“defaultPrototype”,“default.stringsAsFactors”, “dev.cur”,“dev.list”,“dev_packages”,“element_blank”,“empty.dump”, “.First”,“.First.sys”,“flush.console”,“frame”,“getAllConnections”, “getCConverterDescriptions”,“getCConverterStatus”,“geterrmessage”, “get_ll_TOL”,“get_ll_warn”,“getLoadedDLLs”,“getNumCConverters”, “get_path”,“get_Polypath”,“get_PolypathRule”,“get_ReplCRS_warn”, “getRversion”,“getTaskCallbackNames”,“getwd”,“graphics.off”, “has_devel”,“iconvlist”,“is_false”,“is.R”,“is_true”,“Java”, “l10n_info”,“last_plot”,“license”,“license”,“loadedNamespaces”, “loaded_packages”,“loadingNamespaceInfo”,“memory.profile”, “newEmptyObject”,“。NotYetImplemented”,“。OnptRequireMethods”, “plot.new”,“progress_none”,“rc.status”,“Rdoc”,“recordPlot”, “recover”,“。rs.activateGraphicsDevice”,“。rs.createUUID”, “.rs.defaultLibPathIsWriteable”,“。rs.defaultUserLibraryPath”, “.rs.disableQuartz”,“。rs.helprIsActive”,“。rs.iconvcommon”, “.rs.initGraphicsDevice”,“。rs.knitrChunkOptions”, “.rs.listJsonRpcHandlers”,“。rs.packages.initialize”, “.rs.rpc.check_for_package_updates”,“。rs.rpc.get_cran_mirrors”, “.rs.rpc.get_package_install_context”,“。rs.rpc.iconvlist”, “.rs.rpc.init_default_user_library”,“。rs.rpc.list_objects”, “.rs.rpc.list_packages”,“。rs.rpc.remove_all_objects”, “.rs.setHelprLoadHook”,“。rs.sweaveChunkOptions”,“RStudioGD”, “RStudio.version”,“。rs.uniqueLibraryPaths”, “.rs.updatePackageEvents”,“。rs.writeableLibraryPaths”,“Rtangle”, “R.Version”,“RweaveLatex”,“搜索”,“搜索路径”,“sessionData”, “.standard_regexps”,“stderr”,“stdin”,“stdout”,“sys.calls”, “Sys.Date”,“sys.frames”,“Sys.getpid”,“Sys.info”,“Sys.localeconv”, “sys.nframe”,“sys.on.exit”,“sys.parents”,“sys.status”,“系统”, “Sys.time”,“Sys.timezone”,“tempdir”,“test”,“theme_get”,“弃权”