繁体   English   中英

如何为 CRAN 上的所有软件包获取 github repo url?

[英]How to get the github repo url for all the packages on CRAN?

我想为 CRAN 上的所有软件包提取 github repo url。 And I have tried to first read the link of CRAN and get the table of all the package names, which also contains the url for the description page of each package, for I want to extract the github repo url through the description page. 但我无法得到完整的 url。 你能帮我解决这个问题吗? 或者有没有更好的方法来获取所有包的 repo url?

这是我的补充: 实际上,我想过滤确实有官方 github repo 的 pkgs,比如一些 pkgs 为 xfun 或 fddm。 我发现我可以从 CRAN 上的 pkgs 描述中提取用户名和 repo 名称,并将它们放入格式为 url 的 github 中。 (for most of them have the same format url like: https://github.com/{username}/{reponame} . For example, for package xfun , it would be like: https://github.com/yihui/乐趣

现在,我得到了其中一些:(其中三个)

在此处输入图像描述

我想知道我怎么能得到所有这些的 url。 我知道使用胶水 pkg 可以替换 url 中的元素。 为了通过替换元素(用户名和reponame)来获取url,我尝试了map()和map_dfr()function。 但它返回我错误: parse_url(url) 中的错误:length(url) == 1 is not TRUE

这是我的代码:

get <- map_dfr(dat, ~{
  
  username <- dat$user
  reponame <- dat$package
  
pkg_url <- GET(glue::glue("https://github.com/{username}/{reponame}"))

})

你能帮我解决这个问题吗? 非常感谢: :)

我想建议一种不同的方法来到达你想要的地方。

正如评论中所讨论的,并非所有 R 包都有公共 GitHub 存储库。

这是Dirk Eddelbuettel 对另一个问题的回答中的一些代码版本,它从 CRAN 的数据库中检索信息,包括 package 名称和 URL 字段。 如果 package 具有公共 GH 存储库,则作者很可能已在 URL 字段中包含该信息:可能有一些软件包的 GH 存储库信息是可猜测的(即 GH 用户名与(例如) 维护者电子邮件地址中的标识符;GH 存储库名称与 package 名称相同),但要完成所有这些猜测(并访问 GitHub 以查看猜测是否正确)似乎需要做很多工作相对较低的回报。

getPackageRDS <- function() {
     description <- sprintf("%s/web/packages/packages.rds",
                            getOption("repos")["CRAN"])
     con <- if(substring(description, 1L, 7L) == "file://") {
         file(description, "rb")
     } else {
         url(description, "rb")
     }
     on.exit(close(con))
     db <- readRDS(gzcon(con))
     rownames(db) <- NULL
     return(db)
}
dd <- as.data.frame(getPackageRDS())
dd2 <- subset(dd, grepl("github.com", URL))
## clean up (multiple URLs, etc.)
dd2$URL <- sapply(strsplit(dd2$URL,"[, \n]"),
       function(x) trimws(grep("github.com", x, value=TRUE)[1]))

截至今天(2021 年 5 月 25 日),CRAN 上共有 17665 个包,其中 6184 个在 URL 字段中有“github.com”。 以下是前几个结果:

        Package                                           URL
5        abbyyR              http://github.com/soodoku/abbyyR
12     ABCoptim           http://github.com/gvegayon/ABCoptim
16     abctools     https://github.com/dennisprangle/abctools
18        abdiv        https://github.com/kylebittinger/abdiv
20        abess           https://github.com/abess-team/abess
23 ABHgenotypeR http://github.com/StefanReuscher/ABHgenotypeR

URL 字段可能仍然不完全干净,但这应该可以帮助您完成大部分工作。


另一种方法是使用githubinstall package,它通过下载通过抓取 GitHub 寻找 R 包生成的数据帧来工作

library(githubinstall)
dd3 <- gh_list_packages()

目前这个列表中有 34491 个包,所以很明显它包含了很多 CRAN 上没有的东西。 您可以将此包列表与来自available_packages()的信息相交...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM