寻找替代功能

问题描述

最近我发现is.naparent.env可以用作替换函数,因此我们谈论is.na<-parent.env<-。 现在,我想使用一种优雅的方法来搜索此类功能以使其与时俱进(也适用于新软件包)。我知道apropos函数的存在很重要。也许您知道更好的解决方案。

我自己的解决方案:

# better for my case than apropos
replacements <- function(env = NULL,as_func = FALSE) {
  envs_nams <- search()
  envs <- lapply(envs_nams,as.environment)
  names(envs) <- envs_nams 
  if (!is.null(env)) envs <- list(envs[[env]])
  lapply(envs,function(e) if (as_func) mget(Filter(function(x) grepl(".+<-$",x,perl = TRUE),ls(e)),e) 
                           else Filter(function(x) grepl(".+<-$",ls(e)))
}

replacements() # all
replacements(".GlobalEnv") # global
replacements("package:base") # certain
#library(Hmisc)
#replacements("package:Hmisc") # new one

# or for functions
#replacements(as_func = TRUE) # all

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...