Skip to content

Commit 52c24e2

Browse files
committed
Fix get_description_repos
1 parent abf6f2d commit 52c24e2

File tree

8 files changed

+58
-49
lines changed

8 files changed

+58
-49
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
* Revamp `get_hex` and `get_description`
99
- Use lists more consistently
1010
- More robust in general
11+
* `get_description`
12+
- Actually use `use_repos` arg.
1113

1214
# rworkflows 0.99.11
1315

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
get_description_check <- function(dl,
2-
verbose=TRUE){
1+
check_refs_names <- function(dl){
32
### Make sure it gets a name ####
43
if(is.null(unlist(dl))) return(NULL)
54
for(i in seq(length(dl))){
65
nm <- names(dl[i])
7-
if((is.null(nm) || nm=="NULL") &&
8-
methods::is(dl[[i]],"description") ){
9-
names(dl)[i] <- dl[[i]]$get_field("Package")
6+
if(is.null(nm) || nm=="NULL"){
7+
if(methods::is(dl[[i]],"description")){
8+
names(dl)[i] <- dl[[i]]$get_field("Package")
9+
} else if(is.character(dl[[i]])){
10+
names(dl)[i] <- dl[[i]]
11+
}
1012
}
1113
# else if(!is.null(names(dl[i])) && !is.null(dl[[i]]) &&
1214
# basename(names(dl[i]))!=dl[[i]]$get_field("Package")){
@@ -17,4 +19,4 @@ get_description_check <- function(dl,
1719
# }
1820
}
1921
return(dl)
20-
}
22+
}

R/dt_to_desc.R

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,28 @@
1414
#' @importFrom data.table as.data.table
1515
#' @import desc
1616
#' @examples
17-
#' db <- BiocPkgTools::biocPkgList()
17+
#' db <- BiocPkgTools::biocPkgList()
1818
#' dl <- dt_to_desc(db=db, refs="GenomicRanges")
1919
dt_to_desc <- function(db,
2020
refs=NULL,
2121
verbose=TRUE){
2222

2323
Package <- NULL;
2424

25+
refs <- check_refs_names(refs)
2526
db <- data.table::as.data.table(db)
2627
if(is.null(refs)){
2728
refs <- db$Package
2829
}else{
29-
refs <- refs[basename(refs) %in% db$Package]
30+
refs <- refs[basename(names(refs)) %in% db$Package]
3031
}
3132
messager("Constructing DESCRIPTION files for",
32-
formatC(length(refs),big.mark = ","),"R packages.",v=verbose)
33-
valid_fields <-desc::cran_valid_fields
34-
lapply(stats::setNames(basename(refs),
33+
formatC(length(refs),big.mark = ","),"R package(s).",v=verbose)
34+
valid_fields <- desc::cran_valid_fields
35+
lapply(stats::setNames(names(refs),
3536
refs),
3637
function(p){
38+
p <- basename(p)
3739
messager("Constructing DESCRIPTION for:",p,v=verbose)
3840
db_sub <- db[Package==p,][1,]
3941
d <- desc::description$new("!new")
@@ -50,4 +52,4 @@ dt_to_desc <- function(db,
5052
}
5153
d
5254
})
53-
}
55+
}

R/get_description.R

Lines changed: 22 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ get_description <- function(refs=NULL,
3737
which = "cache"),
3838
force_new=FALSE,
3939
use_wd=TRUE,
40-
use_repos=TRUE,
40+
use_repos=FALSE,
4141
verbose=TRUE){
4242
# devoptera::args2vars(get_description)
4343

@@ -47,45 +47,36 @@ get_description <- function(refs=NULL,
4747
refs <- refs_to_list(refs = refs)
4848
paths <- refs_to_list(refs = paths)
4949
if(methods::is(refs[[1]],"description")) {
50-
refs <- get_description_check(dl = refs,
51-
verbose = verbose)
50+
refs <- check_refs_names(dl = refs)
5251
return(refs)
5352
}
5453
if(methods::is(paths[[1]],"description")) {
55-
paths <- get_description_check(dl = paths,
56-
verbose = verbose)
54+
paths <- check_refs_names(dl = paths)
5755
return(paths)
5856
}
5957
if(all(is.na(refs))) refs <- NULL
60-
6158
#### Method 1 ####
62-
dl1 <- get_description_manual(refs=refs,
63-
paths=paths,
64-
cache_dir=cache_dir,
65-
force_new=force_new,
66-
use_wd=use_wd,
67-
verbose=verbose)
68-
dl1 <- get_description_check(dl = dl1,
69-
verbose=verbose)
70-
refs <- names(dl1)
71-
if(!is.null(unlist(dl1))){
72-
if(all(basename(unlist(refs)) %in% basename(names(dl1)))) {
73-
return(dl1)
74-
}
75-
}
7659
if(isFALSE(use_repos) ||
7760
is.null(refs)){
78-
return(dl1)
79-
} else {
80-
#### Method 2 ####
81-
missing_refs <- names(dl1)[unlist(lapply(dl1,is.null))]
82-
for(ref in missing_refs){
83-
dl2 <- get_description_repo(refs=refs,
61+
dl1 <- get_description_manual(refs=refs,
62+
paths=paths,
63+
cache_dir=cache_dir,
64+
force_new=force_new,
65+
use_wd=use_wd,
8466
verbose=verbose)
85-
dl2 <- get_description_check(dl = dl2)
86-
dl1[[ref]] <- dl2[[ref]]
87-
}
67+
dl1 <- check_refs_names(dl = dl1)
8868
return(dl1)
89-
}
90-
69+
refs <- names(dl1)
70+
# if(!is.null(unlist(dl1))){
71+
# if(all(basename(unlist(refs)) %in% basename(names(dl1)))) {
72+
# return(dl1)
73+
# }
74+
# }
75+
} else {
76+
#### Method 2 ####
77+
dl2 <- get_description_repo(refs = refs,
78+
verbose = verbose)
79+
dl2 <- check_refs_names(dl = dl2)
80+
return(dl2)
81+
}
9182
}

R/get_description_repo.R

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,18 @@ get_description_repo <- function(refs = NULL,
3939
saveRDS(db_i, tmp)
4040
}
4141
return(db_i)
42-
}) |> data.table::rbindlist(fill = TRUE, use.names = TRUE, idcol = "r_repo")
43-
if(!is.null(refs)) db <- db[Package %in% basename(refs),]
42+
}) |> data.table::rbindlist(fill = TRUE, use.names = TRUE, idcol = "r_repo")
43+
44+
refs <- check_refs_names(dl = refs)
45+
if(!is.null(refs)) db <- db[Package %in% basename(names(refs)),]
4446
if(nrow(db)==0) {
4547
messager("0 DESCRIPTION files found in CRAN/Bioc.",
4648
"Returning NULL.",v=verbose)
4749
return(NULL)
4850
}
4951
#### Parse GitHub URL #####
50-
db <- get_github_url_db(db = db, return_dt = TRUE)
52+
db <- get_github_url_db(db = db,
53+
return_dt = TRUE)
5154
#### Split GitHub URL ####
5255
db <- cbind(db,BiocPkgTools::githubURLParts(urls = db$url_github))
5356
data.table::setnames(db,c("user_repo","user"),c("owner_repo","owner"),
@@ -73,4 +76,4 @@ get_description_repo <- function(refs = NULL,
7376
# deepdep::deepdep(package = "rworkflows",depth = 2,bioc = TRUE)
7477
# d <- deepdep::get_description(package = "rworkflows")
7578
# deepdep::plot_downloads("htmltools")
76-
}
79+
}

man/get_description.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-get_description.R

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,13 @@ test_that("get_description works", {
6161
testthat::expect_null(d7[[1]])
6262
}
6363

64+
#### Search CRAN/Bioc repos ####
65+
d13 <- get_description(refs="neurogenomics/rworkflows",
66+
use_repos = TRUE)
67+
testthat::expect_equal(d13[[1]],
68+
d1[[1]])
69+
#### Search GitHub repos ####
70+
d14 <- get_description(refs="neurogenomics/orthogene",
71+
use_wd = FALSE)
72+
testthat::expect_true(methods::is(d14[[1]],"description"))
6473
})

vignettes/rworkflows.Rmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ This function creates a banner containing badges,
7373
a hex sticker (if one is available), and author names.
7474

7575
```{r, results='asis'}
76-
badges <- rworkflows::use_badges()
76+
badges <- rworkflows:: use_badges()
7777
```
7878

7979

0 commit comments

Comments
 (0)