Skip to content

Commit ff5a3a1

Browse files
committed
upgrade to 0.99.2
1 parent 3e18711 commit ff5a3a1

15 files changed

+314
-156
lines changed

NAMESPACE

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Generated by roxygen2: do not edit by hand
22

3+
export(add_owner_repo)
34
export(description_extract)
45
export(github_branches)
56
export(github_commits)
@@ -24,6 +25,7 @@ importFrom(data.table,.SD)
2425
importFrom(data.table,as.data.table)
2526
importFrom(data.table,data.table)
2627
importFrom(data.table,dcast)
28+
importFrom(data.table,fcoalesce)
2729
importFrom(data.table,fwrite)
2830
importFrom(data.table,merge.data.table)
2931
importFrom(data.table,rbindlist)
@@ -34,6 +36,7 @@ importFrom(gh,gh_token)
3436
importFrom(methods,is)
3537
importFrom(parallel,mclapply)
3638
importFrom(rworkflows,get_description)
39+
importFrom(rworkflows,get_hex)
3740
importFrom(stats,setNames)
3841
importFrom(stringr,str_split)
3942
importFrom(stringr,str_to_sentence)

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
- `echogithub::description_find` --> `rworkflows::get_description`
77
- `echogithub::github_hex` --> `rworkflows::get_hex`
88
- `echogithub::readme_header` --> `rworkflows::use_badges`
9+
* `r_repos_data`
10+
- Add new arg `add_hex` to find hex URL with `rworkflows::get_hex`.
911

1012
## Bug fixes
1113

R/add_owner_repo.R

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#' Add owner/repo
2+
#'
3+
#' Try to add a new column named "owner_repo" that combines both the owner of
4+
#' and name of each GitHub repository.
5+
#' @param dt \link[data.table]{data.table}.
6+
#' @param add_ref Coalesce multiple columns
7+
#' (\code{e.g. c("owner_repo","repo","package","Package")}) into a single "ref"
8+
#' column. Tries to fill in \code{NA} values as much as possible.
9+
#' @param ref_cols Columns to consider when coalescing into the "ref" column.
10+
#' @param sep Separator value between "owner" and "repo".
11+
#' @returns \link[data.table]{data.table}.
12+
#'
13+
#' @export
14+
#' @examples
15+
#' dt <- data.table::data.table(owner=letters, repo=LETTERS)
16+
#' dt <- add_owner_repo(dt)
17+
add_owner_repo <- function(dt,
18+
add_ref=TRUE,
19+
ref_cols=c("ref","owner_repo","repo",
20+
"package","Package"),
21+
sep="/"){
22+
23+
owner <- repo <- owner_repo <- subaction <- target <- ref <- NULL;
24+
25+
if(!methods::is(dt,"data.table")) dt <- data.table::data.table(dt)
26+
#### Add subaction names ####
27+
if("subaction" %in% names(dt)){
28+
dt[,owner_repo:=gsub("/",sep,subaction)]
29+
} else if(all(c("owner","repo") %in% names(dt))){
30+
dt[,owner_repo:=paste(owner,repo,sep=sep)]
31+
}
32+
default_sep <- "/"
33+
if("target" %in% names(dt) && sep!=default_sep){
34+
dt[,target:=gsub(default_sep,sep,target)]
35+
}
36+
if(all(c("owner","owner_repo") %in% names(dt))){
37+
dt[is.na(owner),owner_repo:=NA]
38+
}
39+
if(all(c("repo","owner_repo") %in% names(dt))){
40+
dt[is.na(repo),owner_repo:=NA]
41+
}
42+
#### Coalesce columns into one "ref" column ####
43+
if(isTRUE(add_ref)){
44+
ref_cols <- ref_cols[ref_cols %in% names(dt)]
45+
dt[,ref:=data.table::fcoalesce(dt[,ref_cols,with=FALSE])]
46+
}
47+
return(dt)
48+
}

R/description_extract.R

Lines changed: 31 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#' @param desc_file When \code{owner} or \code{repo} are NULL,
88
#' these arguments are inferred from the \emph{DESCRIPTION} file.
99
#' @inheritParams rworkflows::get_description
10+
#' @inheritDotParams rworkflows::get_description
1011
#' @inheritParams github_files
1112
#' @inheritParams description_authors
1213
#' @returns A named list or \link[data.table]{data.table}.
@@ -15,83 +16,44 @@
1516
#' @importFrom rworkflows get_description
1617
#' @importFrom data.table as.data.table
1718
#' @examples
18-
#' res <- description_extract(ref="RajLabMSSM/echolocatoR")
19+
#' res <- description_extract(refs="RajLabMSSM/echolocatoR")
1920
description_extract <- function(desc_file = NULL,
20-
ref = NULL,
21+
refs = NULL,
2122
fields = c("owner",
2223
"repo",
2324
"authors"),
2425
names_only = TRUE,
2526
add_html = FALSE,
2627
as_datatable = FALSE,
27-
verbose = TRUE){
28+
nThread = 1,
29+
verbose = TRUE,
30+
...){
2831

29-
# devoptera::args2vars(description_extract)
30-
#### Find or read DESCRIPTION file ####
31-
if(is.null(desc_file)){
32-
desc_file <- rworkflows::get_description(ref = ref,
33-
path = desc_file)
34-
}
35-
force(desc_file)
36-
all_fields <- unique(c("owner","repo","authors","github_url",
37-
desc_file$fields()))
38-
if(is.null(desc_file)) {
39-
stopper("desc_file is required for description_extract")
40-
}
41-
if(is.null(fields)) {
42-
fields <- all_fields
43-
}
44-
fields <- unique(fields)
45-
fields <- fields[fields %in% all_fields]
46-
#### Check package name ####
47-
if(!desc_file$has_fields("Package")){
48-
messager("WARNING:","Package field is missing from DECRIPTION.")
49-
} else {
50-
pkg <- desc_file$get_field("Package")
32+
# devoptera::args2vars(description_extract)
33+
34+
refs <- check_pkgs(pkgs = refs)
35+
if(length(refs)==0 && is.null(desc_file)){
36+
messager("Must supply either refs or desc_file.",
37+
"Returning NULL.",v=verbose)
38+
return(NULL)
5139
}
52-
53-
#### Extract info ####
54-
messager("Extracting",length(fields),"DESCRIPTION field(s)",
55-
"for the package:",pkg,v=verbose)
56-
res <- lapply(stats::setNames(fields,
57-
fields),
58-
function(f){
59-
# messager("Inferring",f,"from DESCRIPTION file.",v=verbose)
60-
#### Check fields ####
61-
if(f %in% author_fields()) {
62-
authors <- description_authors(desc_file = desc_file,
63-
add_html = add_html,
64-
names_only = names_only)
65-
return(authors)
66-
} else if(desc_file$has_fields(f)){
67-
return(desc_file$get_field(f))
68-
} else if(f=="github_url"){
69-
gh_url <- get_github_url(desc_file = desc_file)
70-
return(gh_url)
71-
} else if(f=="owner"){
72-
gh_url <- get_github_url(desc_file = desc_file)
73-
if(is.null(gh_url)) {
74-
return(NULL)
75-
} else {
76-
return(
77-
strsplit(gsub("https://github.com/","",gh_url),"/")[[1]][1]
78-
)
79-
}
80-
} else if(f=="repo"){
81-
gh_url <- get_github_url(desc_file = desc_file)
82-
if(is.null(gh_url)) {
83-
return(NULL)
84-
} else {
85-
return(
86-
strsplit(gsub("https://github.com/","",gh_url),"/")[[1]][2]
87-
)
88-
}
89-
}
90-
})
91-
#### Return ####
92-
if(isTRUE(as_datatable)){
93-
return(data.table::as.data.table(res))
40+
dl <- rworkflows::get_description(refs = refs$package,
41+
paths = desc_file,
42+
verbose = verbose,
43+
...)
44+
meta_desc <- lapply(dl, function(desc_file){
45+
description_extract_i(desc_file= desc_file,
46+
fields = fields,
47+
as_datatable = TRUE,
48+
verbose = FALSE)
49+
}) |>
50+
data.table::rbindlist(fill = TRUE, use.names = TRUE, idcol = "package")
51+
if(nrow(meta_desc)==0){
52+
messager("WARNING: No metadata retrieved from any DESCRIPTION files.",
53+
v=verbose)
9454
} else {
95-
return(res)
96-
}
55+
if("repo" %in% names(meta_desc)) data.table::setkeyv(meta_desc,"repo")
56+
}
57+
return(meta_desc)
58+
9759
}

R/description_extract_i.R

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
description_extract_i <- function(desc_file = NULL,
2+
ref = NULL,
3+
fields = c("owner",
4+
"repo",
5+
"authors"),
6+
names_only = TRUE,
7+
add_html = FALSE,
8+
as_datatable = FALSE,
9+
verbose = TRUE){
10+
#### Find or read DESCRIPTION file ####
11+
12+
if(is.null(desc_file)) {
13+
messager("desc_file is required for description_extract.",
14+
"Returning NULL.",v=verbose)
15+
return(NULL)
16+
}
17+
all_fields <- unique(c("owner","repo","authors","github_url",
18+
desc_file$fields()))
19+
20+
if(is.null(fields)) {
21+
fields <- all_fields
22+
}
23+
fields <- unique(fields)
24+
fields <- fields[fields %in% all_fields]
25+
#### Check package name ####
26+
if(!desc_file$has_fields("Package")){
27+
messager("WARNING:","Package field is missing from DECRIPTION.")
28+
} else {
29+
pkg <- desc_file$get_field("Package")
30+
}
31+
32+
#### Extract info ####
33+
messager("Extracting",length(fields),"DESCRIPTION field(s)",
34+
"for the package:",pkg,v=verbose)
35+
res <- lapply(stats::setNames(fields,
36+
fields),
37+
function(f){
38+
# messager("Inferring",f,"from DESCRIPTION file.",v=verbose)
39+
#### Check fields ####
40+
if(f %in% author_fields()) {
41+
authors <- description_authors(desc_file = desc_file,
42+
add_html = add_html,
43+
names_only = names_only)
44+
return(authors)
45+
} else if(desc_file$has_fields(f)){
46+
return(desc_file$get_field(f))
47+
} else if(f=="github_url"){
48+
gh_url <- get_github_url(desc_file = desc_file)
49+
return(gh_url)
50+
} else if(f=="owner"){
51+
gh_url <- get_github_url(desc_file = desc_file)
52+
if(is.null(gh_url)) {
53+
return(NULL)
54+
} else {
55+
return(
56+
strsplit(gsub("https://github.com/","",gh_url),"/")[[1]][1]
57+
)
58+
}
59+
} else if(f=="repo"){
60+
gh_url <- get_github_url(desc_file = desc_file)
61+
if(is.null(gh_url)) {
62+
return(NULL)
63+
} else {
64+
return(
65+
strsplit(gsub("https://github.com/","",gh_url),"/")[[1]][2]
66+
)
67+
}
68+
}
69+
})
70+
#### Return ####
71+
if(isTRUE(as_datatable)){
72+
return(data.table::as.data.table(res))
73+
} else {
74+
return(res)
75+
}
76+
}

R/description_extract_multi.R

Lines changed: 0 additions & 30 deletions
This file was deleted.

R/github_metadata.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ github_metadata <- function(owner,
3030
return(NULL)
3131
}
3232
messager(paste0(
33-
"Gathering metadata",
33+
"Gathering GitHub metadata",
3434
if(isTRUE(add_traffic))" (with traffic data)" else NULL
3535
),"for repo:",paste(owner,repo,sep="/"),v=verbose)
3636
endpoint <- paste("https://api.github.com","repos",

0 commit comments

Comments
 (0)