【发布时间】:2020-01-14 08:53:56
【问题描述】:
目标:列出某个包的所有包名 - 这里:“ggplot2”
期望的输出:
c(digest, grDevices, grid, gtable, lazyeval, MASS, mgcv, reshape2, rlang, scales, stats, tibble, viridisLite, withr)
我非常接近:
pack <- available.packages()
p <- pack["ggplot2", c("Imports")]
p
"digest, grDevices, grid, gtable (>= 0.1.1), lazyeval, MASS,\nmgcv, reshape2, rlang (>= 0.3.0), scales (>= 0.5.0), stats,\ntibble, viridisLite, withr (>= 2.0.0)"
请看这里:Listing R Package Dependencies Without Installing Packages。
接下来我想替换版本号,例如"(>= 2.0.0)"
我尝试了什么:
library(stringr)
res <- str_match_all(p, " ( (.*?) )")
res <- str_match_all(p, " [(] (.*?) [)]")
【问题讨论】:
-
有点不清楚...对于
ggplot2的情况,您的预期输出是什么? -
你可以像这样使用 gtools,如果我理解正确的话,
gtools::getDependencies('ggplot2')
标签: r