gpt4 book ai didi

regex - 有没有办法获取名称与给定正则表达式匹配的所有函数的列表?

转载 作者:行者123 更新时间:2023-12-04 02:16:54 25 4
gpt4 key购买 nike

我想获得名称与给定模式匹配的所有函数的列表。例如,我想要所有名称包含“theme_”的函数。

我看过 this post它给出了获取名称向量的解决方案。是否可以使用与函数列表相同的名称而不是名称向量?

最佳答案

对于本地包你可以试试这个:

if (!require("pacman")) install.packages("pacman"); library(pacman)

regex <- "theme_"
packs <- p_lib()

out <- setNames(lapply(packs, function(x){
funs <- try(p_funs(x, character.only=TRUE))
if (inherits(funs, "try-error")) return(character(0))
funs[grepl(regex, funs)]
}), packs)

out[!sapply(out, identical, character(0))]

这是我的输出:

## $cowplot
## [1] "theme_cowplot" "theme_nothing"
##
## $ggplot2
## [1] "theme_blank" "theme_bw" "theme_classic" "theme_get" "theme_gray" "theme_grey" "theme_light" "theme_line" "theme_linedraw" "theme_minimal"
## [11] "theme_rect" "theme_segment" "theme_set" "theme_text" "theme_update"
##
## $gridExtra
## [1] "ttheme_default" "ttheme_minimal"
##
## $plotflow
## [1] "theme_apa" "theme_basic" "theme_black" "theme_map"
##
## $qdap
## [1] "theme_badkitchen" "theme_cafe" "theme_duskheat" "theme_grayscale" "theme_greyscale" "theme_hipster" "theme_nightheat" "theme_norah"

关于regex - 有没有办法获取名称与给定正则表达式匹配的所有函数的列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33283598/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com