Skip to content

Commit

Permalink
Merge pull request #120 from schochastics/description
Browse files Browse the repository at this point in the history
added as_pkgrefs DESCRIPTION (#113)
  • Loading branch information
chainsawriot authored Mar 27, 2023
2 parents a21735f + ea7cb7f commit 53abae2
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
35 changes: 35 additions & 0 deletions R/as_pkgrefs.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ as_pkgrefs.character <- function(x, bioc_version = NULL, ...) {
if(.is_directory(x)) {
return(.extract_pkgrefs_dir(x,bioc_version))
}
if(.is_DESCRIPTION(x)){
return(.extract_pkgrefs_DESCRIPTION(x))
}
return(.normalize_pkgs(pkgs = x, bioc_version = bioc_version))
}

Expand Down Expand Up @@ -88,6 +91,23 @@ as_pkgrefs.sessionInfo <- function(x, ...) {
return(paste0("cran::", handle))
}

.extract_pkgrefs_DESCRIPTION <- function(path){
descr <- read.dcf(path)
types <- colnames(descr)
refs <- c()
if("Imports"%in%types){
imports <- descr[,"Imports"]
imports <- strsplit(imports,",[\n]*")[[1]]
refs <- c(refs,paste0("cran::",gsub("\\(.*\\)","",imports)))
}
if("Remotes"%in%types){
remotes <- descr[,"Remotes"]
remotes <- strsplit(remotes,",[\n]*")[[1]]
refs <- c(refs,paste0("github::",gsub("\\(.*\\)","",remotes)))
}
trimws(refs,"both")
}

.is_renv_lockfile <- function(path) {
# assuming all renv lockfiles are called renv.lock and path is only length 1
if(length(path)!=1) {
Expand Down Expand Up @@ -123,3 +143,18 @@ as_pkgrefs.sessionInfo <- function(x, ...) {
warning("scanning directories for R packages cannot detect github packages.",call. = FALSE)
return(.normalize_pkgs(pkgs = pkgs, bioc_version = bioc_version))
}

.is_DESCRIPTION <- function(path) {
# assuming all DESCRIPTION files are called DESCRIPTION and path is only length 1
if(length(path)!=1) {
return(FALSE)
}
if(isFALSE(file.exists(path))) {
return(FALSE)
}
if (isFALSE(basename(path) == "DESCRIPTION")) {
return(FALSE)
}
TRUE
}

23 changes: 23 additions & 0 deletions tests/testdata/DESCRIPTION
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Package: mzesalike
Title: Xaringan Template With MZES Theme
Version: 0.0.3
Authors@R:
person(given = "Chung-hong",
family = "Chan",
role = c("aut", "cre"),
email = "[email protected]",
comment = c(ORCID = "0000-0002-6232-7530"))
Description: Create professional looking HTML5 slides with MZES theme.
License: GPL-3
Encoding: UTF-8
LazyData: true
Imports:
xaringan,
xaringanExtra (>= 0.0.14),
leaflet,
fontawesome
Remotes:
yihui/xaringan,
chainsawriot/xaringanExtra,
rstudio/fontawesome
RoxygenNote: 7.1.0
10 changes: 10 additions & 0 deletions tests/testthat/test_pkgref.R
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,16 @@ test_that("as_pkgrefs directory", {
expect_equal(res, c("bioc::BiocGenerics", "cran::rtoot"))
})

## as_pkgrefs.character (DESCRIPTION)
test_that("as_pkgrefs DESCRIPTION", {
res <- suppressWarnings(as_pkgrefs("../testdata/DESCRIPTION",bioc_version = "3.16"))
expect_equal(res, c("cran::xaringan", "cran::xaringanExtra", "cran::leaflet", "cran::fontawesome",
"github::yihui/xaringan", "github::chainsawriot/xaringanExtra",
"github::rstudio/fontawesome"))
})



## .is_*

test_that(".is_pkgref", {
Expand Down

0 comments on commit 53abae2

Please sign in to comment.