![](/img/trans.png)
[英]Get the current numbers of CRAN packages and Bioconductor packages
[英]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.