-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #60 from chainsawriot/as_pkgs
as_pkgrefs #55
- Loading branch information
Showing
9 changed files
with
136 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#' Convert Data Structures into Package References | ||
#' | ||
#' This generic function converts several standard data structures into a vector of package references, which in turn | ||
#' can be used as the first argument of the function [resolve()]. This function guessimates the possible sources of the | ||
#' packages. But we strongly recommend manually reviewing the detected packages before using them for [resolve()]. | ||
#' @param x, currently supported data structure(s) are: output from [sessionInfo()], a character vector of package names | ||
#' @param ..., not used | ||
#' @return a vector of package references | ||
#' @export | ||
#' @examples | ||
#' as_pkgrefs(sessionInfo()) | ||
#' if (interactive()) { | ||
#' require(rang) | ||
#' require(pkgsearch) | ||
#' graph <- resolve(as_pkgrefs(sessionInfo())) | ||
#' } | ||
as_pkgrefs <- function(x, ...) { | ||
UseMethod("as_pkgrefs", x) | ||
} | ||
|
||
#' @rdname as_pkgrefs | ||
#' @export | ||
as_pkgrefs.default <- function(x, ...) { | ||
## an exported version of .normalize_pkgs | ||
if (is.numeric(x) || is.logical(x) || is.integer(x)) { | ||
stop("Don't know how to convert this to package references.", call. = FALSE) | ||
} | ||
return(.normalize_pkgs(x)) | ||
} | ||
|
||
#' @rdname as_pkgrefs | ||
#' @export | ||
as_pkgrefs.sessionInfo <- function(x, ...) { | ||
vapply(X = x$otherPkgs, FUN = .extract_pkgref_packageDescription, FUN.VALUE = character(1), USE.NAMES = FALSE) | ||
} | ||
|
||
.extract_pkgref_packageDescription <- function(packageDescription) { | ||
handle <- packageDescription[['Package']] | ||
if ("GithubRepo" %in% names(packageDescription)) { | ||
return(paste0("github::", packageDescription[["GithubUsername"]], "/", packageDescription[["GithubRepo"]])) | ||
} | ||
## uncomment this when #57 is implemented | ||
##if (basename(attr(packageDescription, "file")) == "DESCRIPTION") { | ||
## probably load via devtools::load_all | ||
## return(paste0("local::", dirname(attr(packageDescription, "file")))) | ||
##} | ||
## TODO bioc | ||
## if (basename(attr(packageDescription, "file")) == "package.rds") { | ||
return(paste0("cran::", handle)) | ||
## } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters