1

如何找到base具有给定形式参数签名的所有函数(在当前工作环境中可用,因此加上加载的包)?

这是因为我试图找到一个例子来回答这个问题:如果 function(x) 可以工作,我们为什么需要 function()?

4

1 回答 1

1

所需件数:

  • 所有函数的特征向量:apropos("^",mode="function")
  • 函数没有参数吗?length(formals(x))==0
  • 抓取由字符向量命名的对象lapply( x, get )

感谢@RichieCotton 的apropos和 @hadley 的is.primitive.

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”、“日期”、“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”、“licence” 、“许可证”、“loadedNamespaces”、“loaded_pa​​ckages”、“loadingNamespaceInfo”、“memory.profile”、“newEmptyObject”、“.NotYetImplemented”、“.OptRequireMethods”、“plot.new”、“progress_none”、“rc.状态”、“Rdoc”、“recordPlot”、“恢复”、“.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", "System", "Sys.time", “Sys.timezone”、“tempdir”、“test”、“theme_get”、“waiver”sys.nframe”、“sys.on.exit”、“sys.parents”、“sys.status”、“System”、“Sys.time”、“Sys.timezone”、“tempdir”、“test”、“ theme_get", "弃权"sys.nframe”、“sys.on.exit”、“sys.parents”、“sys.status”、“System”、“Sys.time”、“Sys.timezone”、“tempdir”、“test”、“ theme_get", "弃权"

于 2013-02-14T21:27:00.863 回答