Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added as_pkgrefs DESCRIPTION (#113) #120

Merged
merged 1 commit into from
Mar 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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