Skip to content

Commit 3e18711

Browse files
committed
Depends on rworkflows functions. Fix bug in r_repos_data
1 parent e3071ae commit 3e18711

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+389
-788
lines changed

.github/workflows/rworkflows.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,6 @@ jobs:
2929
r: latest
3030
bioc: release
3131
steps:
32-
- if: ${{ env.ACT }}
33-
name: Hack container for local development
34-
run: |
35-
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
36-
sudo apt-get install -y nodejs
37-
shell: bash {0}
3832
- uses: neurogenomics/rworkflows@master
3933
with:
4034
run_bioccheck: ${{ false }}

DESCRIPTION

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: echogithub
22
Type: Package
33
Title: echoverse module: Extract data and metadata from GitHub
4-
Version: 0.99.1
4+
Version: 0.99.2
55
Authors@R:
66
c(person(given = "Brian",
77
family = "Schilder",
@@ -33,20 +33,18 @@ Imports:
3333
gh,
3434
data.table,
3535
stringr,
36-
testthat (>= 3.0.0),
3736
RCurl,
3837
rvest,
39-
parallel
38+
parallel,
39+
rworkflows
4040
Suggests:
4141
markdown,
42-
rmarkdown,
43-
magick,
42+
rmarkdown,
43+
testthat (>= 3.0.0),
4444
remotes,
4545
knitr,
4646
BiocStyle,
4747
covr,
48-
badger,
49-
hexSticker,
5048
httr,
5149
BiocManager,
5250
githubinstall,

NAMESPACE

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
# Generated by roxygen2: do not edit by hand
22

33
export(description_extract)
4-
export(description_find)
54
export(github_branches)
65
export(github_commits)
76
export(github_dependencies)
87
export(github_dependents)
98
export(github_files)
109
export(github_files_download)
11-
export(github_hex)
1210
export(github_metadata)
1311
export(github_pages)
1412
export(github_pages_files)
@@ -20,7 +18,6 @@ export(r_repos)
2018
export(r_repos_data)
2119
export(r_repos_downloads)
2220
export(r_repos_opts)
23-
export(readme_header)
2421
importFrom(RCurl,url.exists)
2522
importFrom(data.table,":=")
2623
importFrom(data.table,.SD)
@@ -36,12 +33,11 @@ importFrom(gh,gh)
3633
importFrom(gh,gh_token)
3734
importFrom(methods,is)
3835
importFrom(parallel,mclapply)
36+
importFrom(rworkflows,get_description)
3937
importFrom(stats,setNames)
4038
importFrom(stringr,str_split)
4139
importFrom(stringr,str_to_sentence)
42-
importFrom(testthat,is_testing)
4340
importFrom(utils,available.packages)
4441
importFrom(utils,capture.output)
4542
importFrom(utils,download.file)
4643
importFrom(utils,installed.packages)
47-
importFrom(utils,packageDescription)

NEWS.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
1+
# echogithub 0.99.2
2+
3+
## New features
4+
5+
* Replace functions that have since been offloaded and improved in `rworkflows`
6+
- `echogithub::description_find` --> `rworkflows::get_description`
7+
- `echogithub::github_hex` --> `rworkflows::get_hex`
8+
- `echogithub::readme_header` --> `rworkflows::use_badges`
9+
10+
## Bug fixes
11+
12+
* `github_dependents`
13+
- Gather deps from all pages (not just the first one).
14+
* `description_authors`
15+
- Fix to handle more complex situations
16+
without explicit naming of each field.
17+
* `r_repos_data`
18+
- Add a check for find R packages that are on GitHub but just not available
19+
via `githubinstall` (which is a lot, since it became outdated years ago).
20+
21+
122
# echogithub 0.99.1
223

324
## New features

R/author_fields.R

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
author_fields <- function(){
2+
c("Authors@R","authors","Authors","author","Author")
3+
}

R/description_authors.R

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,42 @@
1+
#' Description authors
2+
#'
3+
#' Parse authors from the \emph{DESCRIPTION} file of an R package.
4+
#' @param names_only Only return author names (and not other subfields).
5+
#' For example:
6+
#' "Jim Hester \<james.f.hester\@gmail.com\> \[aut\]" would become
7+
#' "Jim Hester".
8+
#' @inheritParams description_extract
9+
#' @returns Authors as an HTML character string.
10+
#'
11+
#' @keywords internal
112
description_authors <- function(desc_file,
2-
add_html=TRUE){
13+
names_only=TRUE,
14+
add_html=FALSE,
15+
verbose=TRUE){
16+
# desc_file <- desc::desc(package = "desc")
17+
# devoptera::args2vars(description_authors)
318

4-
auths <- eval(parse(text = gsub('person','c',desc_file$`Authors@R`)));
5-
authors <- paste(auths[names(auths)=='given'],
6-
auths[names(auths)=='family'], collapse = ', ')
19+
afields <- author_fields()
20+
afields <- afields[afields %in% desc_file$fields()][1]
21+
if(length(afields)>0){
22+
if(grepl("authors",afields,ignore.case = TRUE)){
23+
authors <- desc_file$get_authors()
24+
} else {
25+
authors <- desc_file$get_author()
26+
if(is.null(authors)){
27+
authors <- desc_file$get_field(afields)
28+
}
29+
}
30+
} else {
31+
message("No author fields detected. Returning NULL.",v=verbose)
32+
return(NULL)
33+
}
34+
if(isTRUE(names_only)){
35+
authors <- gsub("(\\([^()]*\\)|\\[[^\\[\\]*\\]|<[^<>]*>)", "",
36+
authors) |>trimws()
37+
}
38+
#### collapse ####
39+
authors <- paste(authors,collapse = ", ")
740
if(isTRUE(add_html)){
841
return(paste0("<h4>Authors: <i>",authors,"</i></h4>"))
942
} else {

R/description_extract.R

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,37 @@
44
#' @param fields Fields to extract.
55
#' @param add_html Add HTML styling to certain fields (e.g "authors").
66
#' @param as_datatable Convert the results into a \link[data.table]{data.table}.
7-
#' @inheritParams description_find
7+
#' @param desc_file When \code{owner} or \code{repo} are NULL,
8+
#' these arguments are inferred from the \emph{DESCRIPTION} file.
9+
#' @inheritParams rworkflows::get_description
810
#' @inheritParams github_files
11+
#' @inheritParams description_authors
912
#' @returns A named list or \link[data.table]{data.table}.
1013
#'
1114
#' @export
15+
#' @importFrom rworkflows get_description
1216
#' @importFrom data.table as.data.table
1317
#' @examples
14-
#'\dontrun{
15-
#' res <- description_extract(repo="echolocatoR")
16-
#'}
18+
#' res <- description_extract(ref="RajLabMSSM/echolocatoR")
1719
description_extract <- function(desc_file = NULL,
18-
repo = NULL,
20+
ref = NULL,
1921
fields = c("owner",
2022
"repo",
2123
"authors"),
24+
names_only = TRUE,
2225
add_html = FALSE,
2326
as_datatable = FALSE,
2427
verbose = TRUE){
28+
29+
# devoptera::args2vars(description_extract)
2530
#### Find or read DESCRIPTION file ####
2631
if(is.null(desc_file)){
27-
desc_file <- description_find(repo = repo,
28-
desc_file = desc_file,
29-
verbose = verbose)
32+
desc_file <- rworkflows::get_description(ref = ref,
33+
path = desc_file)
3034
}
3135
force(desc_file)
3236
all_fields <- unique(c("owner","repo","authors","github_url",
33-
names(desc_file)))
37+
desc_file$fields()))
3438
if(is.null(desc_file)) {
3539
stopper("desc_file is required for description_extract")
3640
}
@@ -39,19 +43,28 @@ description_extract <- function(desc_file = NULL,
3943
}
4044
fields <- unique(fields)
4145
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")
51+
}
52+
4253
#### Extract info ####
43-
messager("Extracting",length(fields),"field(s).",v=verbose)
54+
messager("Extracting",length(fields),"DESCRIPTION field(s)",
55+
"for the package:",pkg,v=verbose)
4456
res <- lapply(stats::setNames(fields,
4557
fields),
4658
function(f){
4759
# messager("Inferring",f,"from DESCRIPTION file.",v=verbose)
4860
#### Check fields ####
49-
if(f %in% c("authors","Authors@R","Author")) {
61+
if(f %in% author_fields()) {
5062
authors <- description_authors(desc_file = desc_file,
51-
add_html = add_html)
63+
add_html = add_html,
64+
names_only = names_only)
5265
return(authors)
53-
} else if(f %in% names(desc_file)){
54-
return(desc_file[[f]])
66+
} else if(desc_file$has_fields(f)){
67+
return(desc_file$get_field(f))
5568
} else if(f=="github_url"){
5669
gh_url <- get_github_url(desc_file = desc_file)
5770
return(gh_url)
@@ -60,14 +73,18 @@ description_extract <- function(desc_file = NULL,
6073
if(is.null(gh_url)) {
6174
return(NULL)
6275
} else {
63-
return(rev(strsplit(gh_url,"/")[[1]])[2])
76+
return(
77+
strsplit(gsub("https://github.com/","",gh_url),"/")[[1]][1]
78+
)
6479
}
6580
} else if(f=="repo"){
6681
gh_url <- get_github_url(desc_file = desc_file)
6782
if(is.null(gh_url)) {
6883
return(NULL)
6984
} else {
70-
return(rev(strsplit(gh_url,"/")[[1]])[1])
85+
return(
86+
strsplit(gsub("https://github.com/","",gh_url),"/")[[1]][2]
87+
)
7188
}
7289
}
7390
})

R/description_extract_multi.R

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,30 @@
11
description_extract_multi <- function(pkgs,
22
nThread=1,
3+
fields=NULL,
34
verbose=TRUE){
45
requireNamespace("parallel")
6+
repo <- package <- NULL;
57

68
pkgs <- check_pkgs(pkgs = pkgs)
7-
meta_desc <- parallel::mclapply(pkgs$package,
9+
if(length(pkgs$package)==0){
10+
messager("pkgs is an empty data.table. Returning NULL.",v=verbose)
11+
}
12+
meta_desc <- parallel::mclapply(stats::setNames(pkgs$package,
13+
pkgs$package),
814
function(p){
915
tryCatch({
10-
description_extract(repo = p,
11-
fields = NULL,
16+
description_extract(ref = p,
17+
fields = fields,
1218
as_datatable = TRUE,
1319
verbose = FALSE)
1420
}, error=function(e){messager(e,v=verbose);NULL})
1521
}, mc.cores = nThread) |>
16-
data.table::rbindlist(fill = TRUE) |>
17-
data.table::setnames("Package","package",
18-
skip_absent = TRUE)
22+
data.table::rbindlist(fill = TRUE, use.names = TRUE, idcol = "package")
1923
if(nrow(meta_desc)==0){
2024
messager("WARNING: No metadata retrieved from any DESCRIPTION files.",
2125
v=verbose)
2226
} else {
23-
data.table::setkeyv(meta_desc,"package")
24-
}
27+
if("repo" %in% names(meta_desc)) data.table::setkeyv(meta_desc,"repo")
28+
}
2529
return(meta_desc)
2630
}

R/description_find.R

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

0 commit comments

Comments
 (0)