-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
17 changed files
with
125 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,54 @@ | ||
#' @title Get GitHub URLs for a set of package names (if they exist). | ||
#' | ||
#' @description | ||
#' Looks at both Package URL and BugReports URL, returns GitHub URL if present in either. | ||
#' | ||
#' @param packages character vector of CRAN package names - case-sensitive. | ||
#' | ||
#' @return a vector of URLs. | ||
#' @export | ||
#' @examples | ||
#' | ||
#' getGitHub("dplyr") | ||
|
||
getGitHub <- function(packages){ | ||
|
||
inCran(packages) | ||
|
||
cran_urls <- cran %>% | ||
dplyr::filter(package %in% packages) %>% | ||
dplyr::select(package, url, bugreports) | ||
|
||
url <- cran_urls$url[2] #temp | ||
find_github <- function(url){ | ||
url <- gsub("\n", ",", url) | ||
url <- gsub("^ | $", "", url) | ||
url <- gsub(" ", ",", url) | ||
url <- gsub("https", "http", url) | ||
url <- gsub("http", "https", url) | ||
url_list <- stringr::str_split(url, ",")[[1]] | ||
github_url <- url_list[stringr::str_detect(url_list, "//github.com")] | ||
github_url <- ifelse(length(github_url) == 0, NA, github_url) | ||
github_url <- ifelse(stringr::str_sub(github_url, -1) == "/", stringr::str_sub(github_url, 1, -2), github_url) | ||
return(github_url) | ||
} | ||
|
||
|
||
cran_urls %>% | ||
dplyr::mutate(url_git = purrr::map_chr(url, find_github), | ||
bug_git = purrr::map_chr(bugreports, find_github) %>% stringr::str_replace("/issues",""), | ||
github_url = ifelse(is.na(url_git), bug_git, url_git) | ||
) %>% | ||
dplyr::select(package, github_url) %>% | ||
dplyr::mutate(ongithub = !is.na(github_url)) | ||
|
||
} | ||
|
||
inCran <- function(package){ | ||
#stopifnot(package %in% cran$package) | ||
if(! (package %in% cran$package )) stop("Package ", package, " not in CRAN. Only supply packages that exists in CRAN") | ||
} | ||
|
||
|
||
#' @title Get GitHub URLs for a set of package names (if they exist). | ||
#' | ||
#' @description | ||
#' Looks at both Package URL and BugReports URL, returns GitHub URL if present in either. | ||
#' | ||
#' @param packages character vector of CRAN package names - case-sensitive. | ||
#' | ||
#' @return a vector of URLs. | ||
#' @export | ||
#' @examples | ||
#' | ||
#' getGitHub("dplyr") | ||
|
||
getGitHub <- function(packages, forget = FALSE){ | ||
|
||
inCran(packages, forget) | ||
# Don't need forget parameter, since forget =TRUE would have | ||
# been triggered in inCran | ||
cran_urls <- get_cran() %>% | ||
dplyr::filter(package %in% packages) %>% | ||
dplyr::select(package, url, bugreports) | ||
|
||
url <- cran_urls$url[2] #temp | ||
find_github <- function(url){ | ||
url <- gsub("\n", ",", url) | ||
url <- gsub("^ | $", "", url) | ||
url <- gsub(" ", ",", url) | ||
url <- gsub("https", "http", url) | ||
url <- gsub("http", "https", url) | ||
url_list <- stringr::str_split(url, ",")[[1]] | ||
github_url <- url_list[stringr::str_detect(url_list, "//github.com")] | ||
github_url <- ifelse(length(github_url) == 0, NA, github_url) | ||
github_url <- ifelse(stringr::str_sub(github_url, -1) == "/", stringr::str_sub(github_url, 1, -2), github_url) | ||
return(github_url) | ||
} | ||
|
||
|
||
cran_urls %>% | ||
dplyr::mutate(url_git = purrr::map_chr(url, find_github), | ||
bug_git = purrr::map_chr(bugreports, find_github) %>% stringr::str_replace("/issues",""), | ||
github_url = ifelse(is.na(url_git), bug_git, url_git) | ||
) %>% | ||
dplyr::select(package, github_url) %>% | ||
dplyr::mutate(ongithub = !is.na(github_url)) | ||
|
||
} | ||
|
||
inCran <- function(package, forget = FALSE){ | ||
cran = get_cran(forget) | ||
#stopifnot(package %in% cran$package) | ||
if(! (package %in% cran$package )) stop("Package ", package, " not in CRAN. Only supply packages that exists in CRAN") | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
get_memoise_cran <- memoise::memoise( | ||
function() { | ||
cran <- tools::CRAN_package_db() | ||
# remove first instance of column name MD5Sum | ||
cran <- cran[, -dplyr::first(which(names(cran) == "MD5sum"))] | ||
|
||
# make it a tibble | ||
cran <- dplyr::tbl_df(cran) | ||
cran <- cran %>% | ||
janitor::clean_names() %>% | ||
janitor::remove_empty_cols() | ||
cran | ||
} | ||
) | ||
|
||
|
||
|
||
#' Get CRAN Packages | ||
#' | ||
#' Returns a tibble containing the current CRAN pacakges. | ||
#' For efficiency reasons, the tibble is cached, so future calls will just return | ||
#' the original tibble. | ||
#' @param forget logical, default \code{FALSE}. Reset the CRAN package cache. | ||
#' @export | ||
#' @examples | ||
#' @importFrom memoise memoise forget | ||
#' cran <- get_cran() | ||
get_cran <- function(forget = FALSE) { | ||
if(forget) | ||
memoise::forget(get_memoise_cran) | ||
get_memoise_cran() | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.