From 399ec3a7e1c643ef529343c9cbdf601ce1361aa7 Mon Sep 17 00:00:00 2001 From: Eric Milliman Date: Thu, 15 Jul 2021 16:19:52 -0400 Subject: [PATCH 01/50] fixed typo --- R/pkg_ref_class.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/pkg_ref_class.R b/R/pkg_ref_class.R index 30c4082c..13148778 100644 --- a/R/pkg_ref_class.R +++ b/R/pkg_ref_class.R @@ -267,7 +267,7 @@ verify_pkg_source <- function(x, source, repos) { switch(source, pkg_install = "pkg_install", pkg_source = { - ## Check source pakcage is present if source is "pkg_source" + ## Check source package is present if source is "pkg_source" if(source == "pkg_source" && !dir.exists(x)){ warning(paste0(c("Package source: `", x, "` does not exist, source is now 'pkg_missing'"))) return("pkg_missing") From c63a5513e3c57bb2323bd62f92a9b6c9b5b5430e Mon Sep 17 00:00:00 2001 From: Eric Milliman Date: Thu, 15 Jul 2021 16:20:27 -0400 Subject: [PATCH 02/50] switched to lapply in place of sapply --- R/assess_dependencies.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/assess_dependencies.R b/R/assess_dependencies.R index 232112e6..0e87c1f6 100644 --- a/R/assess_dependencies.R +++ b/R/assess_dependencies.R @@ -81,7 +81,7 @@ get_package_dependencies <- function(name, repo){ ap <- available.packages(repo = repo) deps <- ap[rownames(ap)==name, c("LinkingTo","Imports","Depends")] deps <- deps[!is.na(deps)] - deps <- sapply(strsplit(deps, ","), trimws) + deps <- lapply(strsplit(deps, ","), trimws) deps <- data.frame(package=unlist(deps), type=rep(names(deps), sapply(deps, length)), stringsAsFactors = FALSE, From e9dd3789bb06980b2e0ce28156d1fe48b1f4b131 Mon Sep 17 00:00:00 2001 From: Eric Milliman Date: Thu, 15 Jul 2021 16:20:44 -0400 Subject: [PATCH 03/50] initial cohort_ref class prototype --- R/cohort_ref_class.R | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 R/cohort_ref_class.R diff --git a/R/cohort_ref_class.R b/R/cohort_ref_class.R new file mode 100644 index 00000000..652a3453 --- /dev/null +++ b/R/cohort_ref_class.R @@ -0,0 +1,39 @@ +#' Cohort ref class +#' +#' This is a class to hold a list of pkg_refs along with extra +#' information regarding the environment a set of pkg_refs is to be installed into. +#' +#' @export +#' @family cohort_ref +#' +cohort_ref <- function(x, library, ...){ + if (missing(x)) return(structure(list(pkg_ref_list = list(logical(0L)), + library = logical(0L)), class = "cohort_ref")) + as_cohort_ref(x, library, ...) +} + +new_cohort_ref <- function(x, library, ...){ + dots <- list(...) + if (length(dots) && is.null(names(dots)) || any(names(dots) == "")) + stop("cohort_ref ellipses arguments must be named") + if(is.character(x) | all(sapply(x, class) != "pkg_ref")){ + x <- pkg_ref(x) + } + cohort_data <- list(x, library=library, dots) + structure(cohort_data, class = "cohort_ref") +} + +make_library <- function(x){ + if(x=="install"){ + return(install.packages()) + } else if(grepl("/.+/.+/", x)){ + + } else if(length(x) > 1 & is.character(x)){ + + } else{ + return(available.packages()) + } + +} + + From 14b9545f63adf4f7b390782c526db29eda9a2a35 Mon Sep 17 00:00:00 2001 From: Eric Milliman Date: Mon, 19 Jul 2021 16:11:29 -0400 Subject: [PATCH 04/50] fixed typos in documentation --- R/cohort_ref_class.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/cohort_ref_class.R b/R/cohort_ref_class.R index 652a3453..ad636d98 100644 --- a/R/cohort_ref_class.R +++ b/R/cohort_ref_class.R @@ -1,7 +1,7 @@ #' Cohort ref class #' #' This is a class to hold a list of pkg_refs along with extra -#' information regarding the environment a set of pkg_refs is to be installed into. +#' information about the environment the packages are to be used/installed in. #' #' @export #' @family cohort_ref From dbc5ae57e32c3f0e0a8980c1f11e001b377df01d Mon Sep 17 00:00:00 2001 From: Eric Milliman Date: Thu, 12 Aug 2021 14:05:53 -0400 Subject: [PATCH 05/50] created shell for a cohort ref class, updated exported namespace assessment. --- R/assess_exported_namespace.R | 10 ++++++++-- R/assess_reverse_dependencies.R | 10 ++++++++++ R/cohort_ref_class.R | 9 ++++++--- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/R/assess_exported_namespace.R b/R/assess_exported_namespace.R index 96ea1c00..db955f33 100644 --- a/R/assess_exported_namespace.R +++ b/R/assess_exported_namespace.R @@ -17,8 +17,8 @@ attributes(assess_exported_namespace)$label <- "Objects exported by package" #' @export assess_exported_namespace.default <- function(x, ...) { as_pkg_metric_na( - pkg_metric(class = "pkg_metric_export_help"), - message = sprintf("Cannot export namesapce from a %s", x$source)) + pkg_metric(class = "pkg_metric_exported_namespace"), + message = sprintf("Cannot export namespace from a %s", x$source)) } #' @export @@ -37,6 +37,12 @@ assess_exported_namespace.pkg_source <- function(x, ...) { }) } +#' @export +assess_exported_namespace.cohort_ref <- function(x, ...) { + +} + + #' Score a package for the number of exported objects #' #' Count the number of exported objects (excluding S3Methods) and divide by 100 diff --git a/R/assess_reverse_dependencies.R b/R/assess_reverse_dependencies.R index a03269d2..eaeb1fd5 100644 --- a/R/assess_reverse_dependencies.R +++ b/R/assess_reverse_dependencies.R @@ -23,6 +23,16 @@ assess_reverse_dependencies.default <- function(x, ...){ ) } +#' @importFrom devtools revdep +#' @export +assess_reverse_dependencies.cohort_ref <- function(x, ...){ + cohort_rev_deps <- devtools::revdep(x$cohort$name, bioconductor = TRUE) + lib_pkgs <- sapply(cohort$library, function(x) x$name) + pkg_metric_eval(class = "cohort_metric_reverse_dependencies", + cohort_rev_deps[cohort_rev_deps %in% lib_pkgs] + ) +} + #' Scoring method for number of reverse dependencies a package has #' #' @eval roxygen_score_family("reverse_dependencies", dontrun = TRUE) diff --git a/R/cohort_ref_class.R b/R/cohort_ref_class.R index ad636d98..f7047f67 100644 --- a/R/cohort_ref_class.R +++ b/R/cohort_ref_class.R @@ -9,7 +9,7 @@ cohort_ref <- function(x, library, ...){ if (missing(x)) return(structure(list(pkg_ref_list = list(logical(0L)), library = logical(0L)), class = "cohort_ref")) - as_cohort_ref(x, library, ...) + new_cohort_ref(x, library, ...) } new_cohort_ref <- function(x, library, ...){ @@ -17,9 +17,12 @@ new_cohort_ref <- function(x, library, ...){ if (length(dots) && is.null(names(dots)) || any(names(dots) == "")) stop("cohort_ref ellipses arguments must be named") if(is.character(x) | all(sapply(x, class) != "pkg_ref")){ - x <- pkg_ref(x) + x <- lapply(x, pkg_cran, repos = "https://cran.rstudio.com") } - cohort_data <- list(x, library=library, dots) + if(is.character(library) | all(sapply(library, class) != "pkg_ref")){ + library <- pkg_ref(library) + } + cohort_data <- list(cohort = x, library=library, dots) structure(cohort_data, class = "cohort_ref") } From d3f8bb9717104e79b44cec46745c92c55db0ccfe Mon Sep 17 00:00:00 2001 From: Eric Milliman Date: Wed, 1 Sep 2021 11:55:33 -0400 Subject: [PATCH 06/50] fixed some iteration errors in assess_reverse_dependencies for cohorts --- R/assess_reverse_dependencies.R | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/R/assess_reverse_dependencies.R b/R/assess_reverse_dependencies.R index eaeb1fd5..5b21591f 100644 --- a/R/assess_reverse_dependencies.R +++ b/R/assess_reverse_dependencies.R @@ -26,10 +26,14 @@ assess_reverse_dependencies.default <- function(x, ...){ #' @importFrom devtools revdep #' @export assess_reverse_dependencies.cohort_ref <- function(x, ...){ - cohort_rev_deps <- devtools::revdep(x$cohort$name, bioconductor = TRUE) - lib_pkgs <- sapply(cohort$library, function(x) x$name) - pkg_metric_eval(class = "cohort_metric_reverse_dependencies", - cohort_rev_deps[cohort_rev_deps %in% lib_pkgs] + #cohort_rev_deps <- devtools::revdep(x$cohort$name, bioconductor = TRUE) + cohort_rev_deps <- lapply(x$cohort, assess_reverse_dependencies) + lib_pkgs <- sapply(x$library, function(x) x$name) + return(lapply(cohort_rev_deps, function(x){ + pkg_metric_eval(class = "cohort_metric_reverse_dependencies", + x[x %in% lib_pkgs] + ) + }) ) } From 31a7751dbf8cc890f10f6c2355775ccfc9c33c32 Mon Sep 17 00:00:00 2001 From: Eric Milliman Date: Wed, 1 Sep 2021 11:55:48 -0400 Subject: [PATCH 07/50] fixed documentation title --- R/assess_exported_namespace.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/assess_exported_namespace.R b/R/assess_exported_namespace.R index db955f33..5f17ea59 100644 --- a/R/assess_exported_namespace.R +++ b/R/assess_exported_namespace.R @@ -1,4 +1,4 @@ -#' Assess a package's results from running R CMD check +#' Assess a package's exported namespace #' #' @eval roxygen_assess_family( #' "exported_namespace", From ae3f132ec12f17bae580eb53cb3948612080816f Mon Sep 17 00:00:00 2001 From: Eric Milliman Date: Tue, 8 Mar 2022 12:42:07 -0500 Subject: [PATCH 08/50] added cohort assessment of dependencies --- R/assess_dependencies.R | 28 +++++++++++++--------------- R/cohort_ref_class.R | 8 ++++++-- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/R/assess_dependencies.R b/R/assess_dependencies.R index 06e15fec..0f78eda4 100644 --- a/R/assess_dependencies.R +++ b/R/assess_dependencies.R @@ -66,6 +66,19 @@ assess_dependencies.pkg_bioc_remote <- function(x, ...){ }) } +assess_dependencies.cohort_ref <- function(x, ...){ + dep <- lapply(x$cohort, assess_dependencies) + nm <- sapply(x$cohort, function(x) x$name) + dep <- data.frame(ref=rep(nm, sapply(dep, nrow)), bind_rows(dep)) + dep$version <- str_extract(dep$package, "(?<=\\().+(?=\\))") + dep$version<- str_extract(dep$version, "\\d+\\.\\d+(\\.\\d+)*") + dep$package <- trimws(gsub("\\(.+\\)", "", dep$package)) + dep2 <- list(minVer = tapply(dep$version, dep$package, function(x) sort(x, decreasing = T)[1]), + minDep = tapply(dep$type, dep$package, function(x) sort(x)[1])) + dep2 <- merge(as.data.frame(dep2$minVer), as.data.frame(dep2$minDep), by="row.names") + return(dep2) +} + #' Score a package for dependencies #' #' Calculates a regularized score based on the number of dependencies a package has. @@ -142,21 +155,6 @@ remove_base_packages <- function(df){ return(deps) } -#' Score a package for dependencies -#' -#' Returns the total number dependencies -#' -#' @eval roxygen_score_family("dependencies") -#' @return A \code{numeric} -#' -#' @export -metric_score.pkg_metric_dependencies <- function(x, ...) { - NROW(x) -} - -attributes(metric_score.pkg_metric_dependencies)$label <- - "The number of package dependencies" - #Helper functions to get extract dependencies #' Gets available packages from necessary repository and filters for diff --git a/R/cohort_ref_class.R b/R/cohort_ref_class.R index f7047f67..6e9a13e7 100644 --- a/R/cohort_ref_class.R +++ b/R/cohort_ref_class.R @@ -16,13 +16,17 @@ new_cohort_ref <- function(x, library, ...){ dots <- list(...) if (length(dots) && is.null(names(dots)) || any(names(dots) == "")) stop("cohort_ref ellipses arguments must be named") + if(is.character(x) | all(sapply(x, class) != "pkg_ref")){ x <- lapply(x, pkg_cran, repos = "https://cran.rstudio.com") } - if(is.character(library) | all(sapply(library, class) != "pkg_ref")){ + + if(!missing(library) && + (is.character(library) | all(sapply(library, class) != "pkg_ref"))){ library <- pkg_ref(library) + cohort_data <- list(cohort = x, library=library, dots) } - cohort_data <- list(cohort = x, library=library, dots) + cohort_data <- list(cohort = x, library=logical(0L), dots) structure(cohort_data, class = "cohort_ref") } From 18c2f6b4867874d2a029ff0977a24bc485d1114a Mon Sep 17 00:00:00 2001 From: Eric Milliman Date: Tue, 8 Mar 2022 17:16:09 -0500 Subject: [PATCH 09/50] beefing up cohort_ref class --- R/cohort_ref_class.R | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/R/cohort_ref_class.R b/R/cohort_ref_class.R index 6e9a13e7..f37b1014 100644 --- a/R/cohort_ref_class.R +++ b/R/cohort_ref_class.R @@ -6,26 +6,29 @@ #' @export #' @family cohort_ref #' -cohort_ref <- function(x, library, ...){ +cohort_ref <- function(x, library, includeDependencies = TRUE, ...){ if (missing(x)) return(structure(list(pkg_ref_list = list(logical(0L)), library = logical(0L)), class = "cohort_ref")) new_cohort_ref(x, library, ...) } -new_cohort_ref <- function(x, library, ...){ +new_cohort_ref <- function(x, library, includeDependencies = includeDependencies...){ dots <- list(...) + if (length(dots) && is.null(names(dots)) || any(names(dots) == "")) stop("cohort_ref ellipses arguments must be named") - if(is.character(x) | all(sapply(x, class) != "pkg_ref")){ + is_a_path <- all(is_path(library)) + if((is.character(x) & length(x)>1) | all(sapply(x, function(y) !"pkg_ref" %in% class(y)))){ x <- lapply(x, pkg_cran, repos = "https://cran.rstudio.com") - } + } else if (class(x) == "list_of_pkg_ref" || all(sapply(x, function(y) "pkg_ref" %in% class(y))) ) if(!missing(library) && (is.character(library) | all(sapply(library, class) != "pkg_ref"))){ - library <- pkg_ref(library) + library <- cohort_data <- list(cohort = x, library=library, dots) } + cohort_data <- list(cohort = x, library=logical(0L), dots) structure(cohort_data, class = "cohort_ref") } @@ -43,4 +46,8 @@ make_library <- function(x){ } - +is_path <- function(x){ + if(is.character(x)){ + return(dir.exists(x)) + } +} From 77d1a43968bb8a8cb0046a35b6848a5dd5aa3370 Mon Sep 17 00:00:00 2001 From: Eric Milliman Date: Tue, 8 Mar 2022 17:20:43 -0500 Subject: [PATCH 10/50] skeletons for two cohort metrics --- R/assess_exported_namespace.R | 1 + R/assess_reverse_dependencies.R | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/R/assess_exported_namespace.R b/R/assess_exported_namespace.R index 232f6d7f..6bd722c2 100644 --- a/R/assess_exported_namespace.R +++ b/R/assess_exported_namespace.R @@ -39,6 +39,7 @@ assess_exported_namespace.pkg_source <- function(x, ...) { #' @export assess_exported_namespace.cohort_ref <- function(x, ...) { + ns <- lapply(x$cohort, assess_exported_namespace) } diff --git a/R/assess_reverse_dependencies.R b/R/assess_reverse_dependencies.R index 92358d82..49f11cf7 100644 --- a/R/assess_reverse_dependencies.R +++ b/R/assess_reverse_dependencies.R @@ -25,7 +25,11 @@ assess_reverse_dependencies.default <- function(x, ...){ assess_reverse_dependencies.cohort_ref <- function(x, ...){ #cohort_rev_deps <- devtools::revdep(x$cohort$name, bioconductor = TRUE) cohort_rev_deps <- lapply(x$cohort, assess_reverse_dependencies) - lib_pkgs <- sapply(x$library, function(x) x$name) + + if(length(x$library){ + lib_pkgs <- sapply(x$library, function(x) x$name) + } + return(lapply(cohort_rev_deps, function(x){ pkg_metric_eval(class = "cohort_metric_reverse_dependencies", x[x %in% lib_pkgs] From a063a2d712f1351dca350e0dc0a2832ebf3f64ba Mon Sep 17 00:00:00 2001 From: Eric Milliman Date: Wed, 23 Mar 2022 18:50:42 -0400 Subject: [PATCH 11/50] create explicit list_of_package_ref constructors. renamed pkg_library to library_ref, and modified its return value to be a list_of_package_ref --- R/pkg_ref_class.R | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/R/pkg_ref_class.R b/R/pkg_ref_class.R index 1750e5a9..c318d1db 100644 --- a/R/pkg_ref_class.R +++ b/R/pkg_ref_class.R @@ -49,8 +49,8 @@ #' #' *Experimental!* #' Package cohorts are structures to determine the risk of a set of packages. -#' `pkg_library()` can be called to create a object containing the pkg_ref -#' objects of all packages in a system library. +#' `library_ref()` can be called to create a object containing the pkg_ref +#' objects of all packages in a library. #' #' #' @rdname pkg_ref @@ -201,13 +201,13 @@ pkg_missing <- function(x) { } #' @rdname pkg_ref -pkg_library <- function(lib.loc) { +library_ref <- function(lib.loc) { # Create pkg_cohort object - cohort <- pkg_cohort() + cohort <- cohort_ref() for(pkg in list.files(lib.loc, recursive = FALSE, full.names = FALSE)) { cohort[[length(cohort)+1]] <- pkg_install(pkg, lib.loc = lib.loc) } - cohort + as_list_of_pkg_ref(cohort) } #' Convert into a package object @@ -374,3 +374,19 @@ verify_pkg_source <- function(x, source, repos) { source } + +#' Coerce a list or pkg_ref to a list_list_of_pkg_ref +#' +#' @importFrom vctrs new_list_of +#' @export +as_list_of_pkg_ref <- function(x){ + return(vctrs::new_list_of(x, ptype = pkg_ref(), class = "list_of_pkg_ref")) +} + +#' Create a list_list_of_pkg_ref from list of pkg_refs +#' +#' @importFrom vctrs new_list_of +#' @export +new_list_of_pkg_ref <- function(x){ + return(vctrs::new_list_of(x, ptype = pkg_ref(), class = "list_of_pkg_ref")) +} From 7da875a55d0aad71723da42856acfd8f1768d5b1 Mon Sep 17 00:00:00 2001 From: Eric Milliman Date: Wed, 23 Mar 2022 18:51:15 -0400 Subject: [PATCH 12/50] fixed missing parantheses --- R/assess_reverse_dependencies.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/assess_reverse_dependencies.R b/R/assess_reverse_dependencies.R index 49f11cf7..5048e17f 100644 --- a/R/assess_reverse_dependencies.R +++ b/R/assess_reverse_dependencies.R @@ -26,7 +26,7 @@ assess_reverse_dependencies.cohort_ref <- function(x, ...){ #cohort_rev_deps <- devtools::revdep(x$cohort$name, bioconductor = TRUE) cohort_rev_deps <- lapply(x$cohort, assess_reverse_dependencies) - if(length(x$library){ + if(length(x$library)){ lib_pkgs <- sapply(x$library, function(x) x$name) } From e27ede84c34e70d8ef961812eac8498d85c1403c Mon Sep 17 00:00:00 2001 From: Eric Milliman Date: Wed, 23 Mar 2022 18:55:13 -0400 Subject: [PATCH 13/50] rewrote cohort_ref constructor. added print and as_tibble functions for cohort_ref class --- R/cohort_ref_class.R | 77 ++++++++++++++++++++++++++++---------------- 1 file changed, 49 insertions(+), 28 deletions(-) diff --git a/R/cohort_ref_class.R b/R/cohort_ref_class.R index f37b1014..f4fbd958 100644 --- a/R/cohort_ref_class.R +++ b/R/cohort_ref_class.R @@ -6,44 +6,49 @@ #' @export #' @family cohort_ref #' -cohort_ref <- function(x, library, includeDependencies = TRUE, ...){ - if (missing(x)) return(structure(list(pkg_ref_list = list(logical(0L)), - library = logical(0L)), class = "cohort_ref")) - new_cohort_ref(x, library, ...) +cohort_ref <- function(x, library = c("base", "recommended","installed"), lib.loc="", includeDependencies = TRUE, ...){ + if (missing(x) & missing(library) & missing(lib.loc)) { + # return(vctrs::new_list_of(cohort=list_of_pkg_ref(), + # library=list_of_pkg_ref(), + # ptype = list_of_pkg_ref(), + # class = "cohort_ref")) + stop("No packages defined for cohort ref") + } + + new_cohort_ref(x, ...) } -new_cohort_ref <- function(x, library, includeDependencies = includeDependencies...){ +new_cohort_ref <- function(x, library="recommended", lib.loc, ...){ dots <- list(...) - if (length(dots) && is.null(names(dots)) || any(names(dots) == "")) + if (length(dots) && is.null(names(dots)) || any(names(dots) == "")){ stop("cohort_ref ellipses arguments must be named") + } - is_a_path <- all(is_path(library)) - if((is.character(x) & length(x)>1) | all(sapply(x, function(y) !"pkg_ref" %in% class(y)))){ - x <- lapply(x, pkg_cran, repos = "https://cran.rstudio.com") - } else if (class(x) == "list_of_pkg_ref" || all(sapply(x, function(y) "pkg_ref" %in% class(y))) ) - - if(!missing(library) && - (is.character(library) | all(sapply(library, class) != "pkg_ref"))){ - library <- - cohort_data <- list(cohort = x, library=library, dots) + if(is.atomic(x) & length(x)>1){ + x <- as_list_of_pkg_ref(lapply(x, pkg_cran, repos = getOption("repos"))) + } else if (class(x) != "list_of_pkg_ref" && + all(sapply(x, function(y) "pkg_ref" %in% class(y)))){ + x <- as_list_of_pkg_ref(x) } - cohort_data <- list(cohort = x, library=logical(0L), dots) - structure(cohort_data, class = "cohort_ref") -} + ip <- as.data.frame(installed.packages()) + if(library=="base"){ + libref <- as_list_of_pkg_ref(lapply(ip$Package[ip$Priority=="base"], pkg_install)) + } else if(library=="recommended"){ + libref <- as_list_of_pkg_ref(lapply(ip$Package[ip$Priority %in% c("base", "recommended")], pkg_install)) + } else if(library=="installed"){ + if(!missing(lib.loc)){ + libref <- as_list_of_pkg_ref(lapply(ip$Package, pkg_install)) + } else{ + ip <- as.data.frame(installed.packages(lib.loc)) + libref <- as_list_of_pkg_ref(lapply(ip$Package, pkg_install)) + } -make_library <- function(x){ - if(x=="install"){ - return(install.packages()) - } else if(grepl("/.+/.+/", x)){ - - } else if(length(x) > 1 & is.character(x)){ - - } else{ - return(available.packages()) } - + return(structure(list(cohort=x, + library=libref, + dots), class = "cohort_ref")) } is_path <- function(x){ @@ -51,3 +56,19 @@ is_path <- function(x){ return(dir.exists(x)) } } + + +#' @importFrom tibble tibble +#' @importFrom dplyr bind_rows +#' @method as_tibble cohort_ref +#' @export +as_tibble.cohort_ref <- function(x, ...) { + dplyr::bind_rows(as_tibble(x$cohort), + as_tibble(x$library)) +} + + +print.cohort_ref <- function(x){ + list(as_tibble(x$cohort), + as_tibble(x$library)) +} From a1550b0df90e1ef5f08b65b50d910c863f63c07f Mon Sep 17 00:00:00 2001 From: Eric Milliman Date: Thu, 24 Mar 2022 16:51:49 -0400 Subject: [PATCH 14/50] remove pkg_cohort function, and replace with cohort_ref (to be consistent with pkg_ref paradigm) --- R/pkg_cohort.R | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 R/pkg_cohort.R diff --git a/R/pkg_cohort.R b/R/pkg_cohort.R deleted file mode 100644 index e660c5d3..00000000 --- a/R/pkg_cohort.R +++ /dev/null @@ -1,7 +0,0 @@ -#' @family pkg_ref -pkg_cohort <- function() { - structure( - list(), - class = "pkg_cohort" - ) -} From 93ff9940441ae71837e6b162d6cdc27c0515e53e Mon Sep 17 00:00:00 2001 From: Eric Milliman Date: Wed, 30 Mar 2022 09:04:20 -0400 Subject: [PATCH 15/50] updated doc and ns --- NAMESPACE | 5 +++++ R/cohort_ref_class.R | 4 +++- man/as_list_of_pkg_ref.Rd | 11 +++++++++++ man/cohort_ref.Rd | 8 +++++++- man/metric_score.pkg_metric_dependencies.Rd | 8 -------- man/new_list_of_pkg_ref.Rd | 11 +++++++++++ man/pkg_ref.Rd | 8 ++++---- 7 files changed, 41 insertions(+), 14 deletions(-) create mode 100644 man/as_list_of_pkg_ref.Rd create mode 100644 man/new_list_of_pkg_ref.Rd diff --git a/NAMESPACE b/NAMESPACE index e30a5dc8..53448ba0 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -12,6 +12,7 @@ S3method(as_pkg_metric,expr_output) S3method(as_pkg_ref,character) S3method(as_pkg_ref,default) S3method(as_pkg_ref,pkg_ref) +S3method(as_tibble,cohort_ref) S3method(as_tibble,list_of_pkg_ref) S3method(as_tibble,pkg_ref) S3method(assess_covr_coverage,default) @@ -73,6 +74,7 @@ S3method(pkg_assess,pkg_ref) S3method(pkg_assess,tbl_df) S3method(pkg_score,list_of_pkg_metric) S3method(pkg_score,tbl_df) +S3method(print,cohort_ref) S3method(print,pkg_ref) S3method(print,with_eval_recording) S3method(summarize_scores,data.frame) @@ -83,6 +85,7 @@ S3method(vec_ptype_abbr,pkg_metric) S3method(vec_ptype_abbr,pkg_ref) S3method(with,pkg_ref) export(all_assessments) +export(as_list_of_pkg_ref) export(as_pkg_metric) export(as_pkg_ref) export(assess_covr_coverage) @@ -109,6 +112,7 @@ export(assessment_error_throw) export(cohort_ref) export(get_assessments) export(metric_score) +export(new_list_of_pkg_ref) export(pkg_assess) export(pkg_metric) export(pkg_ref) @@ -128,6 +132,7 @@ importFrom(cranlogs,cran_downloads) importFrom(curl,nslookup) importFrom(devtools,check) importFrom(devtools,revdep) +importFrom(dplyr,bind_rows) importFrom(httr,GET) importFrom(httr,content) importFrom(memoise,memoise) diff --git a/R/cohort_ref_class.R b/R/cohort_ref_class.R index f4fbd958..65b881e6 100644 --- a/R/cohort_ref_class.R +++ b/R/cohort_ref_class.R @@ -67,7 +67,9 @@ as_tibble.cohort_ref <- function(x, ...) { as_tibble(x$library)) } - +#' @importFrom tibble tibble +#' @method print cohort_ref +#' @export print.cohort_ref <- function(x){ list(as_tibble(x$cohort), as_tibble(x$library)) diff --git a/man/as_list_of_pkg_ref.Rd b/man/as_list_of_pkg_ref.Rd new file mode 100644 index 00000000..c82a823b --- /dev/null +++ b/man/as_list_of_pkg_ref.Rd @@ -0,0 +1,11 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/pkg_ref_class.R +\name{as_list_of_pkg_ref} +\alias{as_list_of_pkg_ref} +\title{Coerce a list or pkg_ref to a list_list_of_pkg_ref} +\usage{ +as_list_of_pkg_ref(x) +} +\description{ +Coerce a list or pkg_ref to a list_list_of_pkg_ref +} diff --git a/man/cohort_ref.Rd b/man/cohort_ref.Rd index 9bb5bed1..0df3ec38 100644 --- a/man/cohort_ref.Rd +++ b/man/cohort_ref.Rd @@ -4,7 +4,13 @@ \alias{cohort_ref} \title{Cohort ref class} \usage{ -cohort_ref(x, library, ...) +cohort_ref( + x, + library = c("base", "recommended", "installed"), + lib.loc = "", + includeDependencies = TRUE, + ... +) } \description{ This is a class to hold a list of pkg_refs along with extra diff --git a/man/metric_score.pkg_metric_dependencies.Rd b/man/metric_score.pkg_metric_dependencies.Rd index df65476a..9aedb4e9 100644 --- a/man/metric_score.pkg_metric_dependencies.Rd +++ b/man/metric_score.pkg_metric_dependencies.Rd @@ -4,8 +4,6 @@ \alias{metric_score.pkg_metric_dependencies} \title{Score a package for dependencies} \usage{ -\method{metric_score}{pkg_metric_dependencies}(x, ...) - \method{metric_score}{pkg_metric_dependencies}(x, ...) } \arguments{ @@ -16,15 +14,11 @@ \value{ numeric value between \code{0} (high number of dependencies) and \code{1} (low number of dependencies) - -A \code{numeric} } \description{ Calculates a regularized score based on the number of dependencies a package has. Convert the number of dependencies \code{NROW(x)} into a validation score [0,1] \deqn{ 1 - 1 / (1 + exp(-0.5 * (NROW(x) + 4))) } - -Returns the total number dependencies } \details{ The scoring function is the classic logistic curve \deqn{ / (1 + exp(-k(x-x[0])) } @@ -36,6 +30,4 @@ and logistic growth rate of \eqn{k = 0.5}. \examples{ \dontrun{metric_score(assess_dependencies(pkg_ref("riskmetric"))) } -\dontrun{metric_score(assess_dependencies(pkg_ref("riskmetric"))) -} } diff --git a/man/new_list_of_pkg_ref.Rd b/man/new_list_of_pkg_ref.Rd new file mode 100644 index 00000000..126450ae --- /dev/null +++ b/man/new_list_of_pkg_ref.Rd @@ -0,0 +1,11 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/pkg_ref_class.R +\name{new_list_of_pkg_ref} +\alias{new_list_of_pkg_ref} +\title{Create a list_list_of_pkg_ref from list of pkg_refs} +\usage{ +new_list_of_pkg_ref(x) +} +\description{ +Create a list_list_of_pkg_ref from list of pkg_refs +} diff --git a/man/pkg_ref.Rd b/man/pkg_ref.Rd index 7902b7e2..54c5d03d 100644 --- a/man/pkg_ref.Rd +++ b/man/pkg_ref.Rd @@ -7,7 +7,7 @@ \alias{pkg_cran} \alias{pkg_bioc} \alias{pkg_missing} -\alias{pkg_library} +\alias{library_ref} \alias{as_pkg_ref} \title{Create a package reference} \usage{ @@ -23,7 +23,7 @@ pkg_bioc(x) pkg_missing(x) -pkg_library(lib.loc) +library_ref(lib.loc) as_pkg_ref(x, ...) } @@ -98,8 +98,8 @@ collection. *Experimental!* Package cohorts are structures to determine the risk of a set of packages. -`pkg_library()` can be called to create a object containing the pkg_ref -objects of all packages in a system library. +`library_ref()` can be called to create a object containing the pkg_ref +objects of all packages in a library. } \examples{ From 3d85369333a5a362bdf3eb604dba3f777b9c43db Mon Sep 17 00:00:00 2001 From: Eric Milliman Date: Wed, 6 Apr 2022 17:09:11 -0400 Subject: [PATCH 16/50] copy pasta of pkg_metric for to cohort metric --- R/cohort_metric.R | 103 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 R/cohort_metric.R diff --git a/R/cohort_metric.R b/R/cohort_metric.R new file mode 100644 index 00000000..df417ca4 --- /dev/null +++ b/R/cohort_metric.R @@ -0,0 +1,103 @@ +#' A helper for structuring assessment return objects for dispatch with the +#' score function +#' +#' @param x data to store as a \code{cohort_metric} +#' @param ... additional attributes to bind to the \code{cohort_metric} object +#' @param class a subclass to differentiate the \code{cohort_metric} object +#' +#' @return a \code{cohort_metric} object +#' +#' @export +cohort_metric <- function(x = NA, ..., class = c()) { + if (is.null(x)) x <- list() + structure(x, ..., class = c(class, "cohort_metric", class(x))) +} + +#' Convert an object to a \code{cohort_metric} +#' +#' @inheritParams pkg_metric +#' @return a \code{cohort_metric} object +#' @export +as_cohort_metric <- function(x, class = c()) { + UseMethod("as_cohort_metric") +} + + + +#' @export +as_cohort_metric.default <- function(x, class = c()) { + cohort_metric(x, class = class) +} + + + +#' @export +as_cohort_metric.expr_output <- function(x, class = c()) { + x_metric <- cohort_metric(x, class = class) + if (is_error(x)) + x_metric <- as_cohort_metric_error(x_metric) + x_metric +} + +#' Evaluate a cohort metric +#' +#' Evalute code relevant to a cohort metric, capturing the evaluated code as well as +#' any messages, warnings or errors that are thrown in the process. +#' +#' @param expr An expression to evaluate in order to calculate a +#' \code{cohort_metric} +#' @param env An environment in which \code{expr} is to be evaluated +#' @inheritParams cohort_metric +#' +#' @return a \code{cohort_metric} object containing the result of \code{expr} +#' @keywords internal +cohort_metric_eval <- function(expr, ..., class = c(), env = parent.frame()) { + out <- capture_expr_output(substitute(expr), env = env, quoted = TRUE) + out_metric <- as_pkg_metric(out, class = class) + if (inherits(out, "error")) out_metric <- as_pkg_metric_error(out_metric) + out_metric +} + +#' @export +format.cohort_metric_error <- function(x, ...) { + class_str <- gsub("^cohort_metric_", "", class(x)[[1]]) + pillar::style_na(paste0("<", class_str, ">")) +} + + + +#' @export +format.cohort_metric <- function(x, ...) { + class_str <- gsub("^cohort_metric_", "", class(x)[[1]]) + data_str <- with_unclassed_to(x, "cohort_metric", pillar::pillar_shaft(x)) + paste0(capture.output(data_str), collapse = "") +} + +#' A subclass wrapping an error with an additional parent class +#' +#' @param error an error condition object to capture +#' +#' @return an error condition object after wrap \code{pkg_metric_error} class. +#' @keywords internal +as_cohort_metric_error <- function(error) { + as_cohort_metric_condition(error, subclass = "cohort_metric_error") +} + +#' A pkg_metric subclass for general metric evaluation conditions +#' +#' @param x an object to wrap in a \code{pkg_metric_condition} class +#' @param ... additional arguments added as attributes to object \code{x} +#' @param subclass an optional subclass of \code{pkg_metric_condition} to +#' include +#' +#' @return an object after wrap \code{pkg_metric_condition} class. +#' @keywords internal +as_cohort_metric_condition <- function(x, ..., subclass = c()) { + dots <- list(...) + if (length(names(dots)) != length(dots)) + stop("All ellipsis arguments must be named") + dots <- dots[setdiff(names(dots), "class")] + attributes(x)[names(dots)] <- dots + class(x) <- c(subclass, "cohort_metric_condition", class(x)) + x +} From 1790e19a0a482fe878bc8bbddc525a1c9366d48d Mon Sep 17 00:00:00 2001 From: Eric Milliman Date: Wed, 6 Apr 2022 17:10:17 -0400 Subject: [PATCH 17/50] reformulation of dependency assess* and refs. In preperation for assess_has_dependency_conflict --- R/assess_dependencies.R | 43 ++++++++++------------------------ R/pkg_ref_cache_dependencies.R | 40 +++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 31 deletions(-) create mode 100644 R/pkg_ref_cache_dependencies.R diff --git a/R/assess_dependencies.R b/R/assess_dependencies.R index 0f78eda4..9e1f25e9 100644 --- a/R/assess_dependencies.R +++ b/R/assess_dependencies.R @@ -26,34 +26,24 @@ assess_dependencies.default <- function(x, ...){ #' @export assess_dependencies.pkg_source <- function(x, ...){ pkg_metric_eval(class = "pkg_metric_dependencies", { - parse_dcf_dependencies(x$path) + NROW(x$dependencies) }) } #' @export assess_dependencies.pkg_install <- function(x, ...){ pkg_metric_eval(class = "pkg_metric_dependencies", { - parse_dcf_dependencies(x$path) + NROW(x$dependencies) }) } #' @export assess_dependencies.pkg_cran_remote <- function(x, ...){ - #Attempt to find CRAN URL by matching all urls returned by getOptions("repos") to memoise_cran_mirrors table - repos <- getOption("repos")[which(getOption("repos") %in% memoise_cran_mirrors()$URL)] - - if(length(repos)==0){ - repos <- grep("[\\.|//]cran\\.", getOption("repos"), ignore.case = T, value = T) - } - if(length(repos)==0){ - repos <- getOption("repos")[["CRAN"]] - } - - if(length(repos)==0){ + if(is.na(x$dependencies)){ as_pkg_metric_error(error = 'Could not determine which CRAN mirror you are using.') } else{ pkg_metric_eval(class = "pkg_metric_dependencies", { - get_package_dependencies(x$name, repo = repos[1]) ##Will use the first CRAN mirror found in the users environment + NROW(x$dependencies) }) } } @@ -61,22 +51,13 @@ assess_dependencies.pkg_cran_remote <- function(x, ...){ #' @importFrom BiocManager repositories #' @export assess_dependencies.pkg_bioc_remote <- function(x, ...){ - pkg_metric_eval(class = "pkg_metric_dependencies", { - get_package_dependencies(x$name, BiocManager::repositories()[1]) - }) -} - -assess_dependencies.cohort_ref <- function(x, ...){ - dep <- lapply(x$cohort, assess_dependencies) - nm <- sapply(x$cohort, function(x) x$name) - dep <- data.frame(ref=rep(nm, sapply(dep, nrow)), bind_rows(dep)) - dep$version <- str_extract(dep$package, "(?<=\\().+(?=\\))") - dep$version<- str_extract(dep$version, "\\d+\\.\\d+(\\.\\d+)*") - dep$package <- trimws(gsub("\\(.+\\)", "", dep$package)) - dep2 <- list(minVer = tapply(dep$version, dep$package, function(x) sort(x, decreasing = T)[1]), - minDep = tapply(dep$type, dep$package, function(x) sort(x)[1])) - dep2 <- merge(as.data.frame(dep2$minVer), as.data.frame(dep2$minDep), by="row.names") - return(dep2) + if(is.na(x$dependencies)){ + as_pkg_metric_error(error = 'Could not determine which BioC mirror you are using.') + } else{ + pkg_metric_eval(class = "pkg_metric_dependencies", { + NROW(x$dependencies) + }) + } } #' Score a package for dependencies @@ -97,7 +78,7 @@ assess_dependencies.cohort_ref <- function(x, ...){ #' #' @export metric_score.pkg_metric_dependencies <- function(x, ...) { - 1 - 1/(1 + exp(-0.5 * (NROW(x) - 4))) + 1 - 1/(1 + exp(-0.5 * (x - 4))) } attributes(metric_score.pkg_metric_dependencies)$label <- "The number of package dependencies" diff --git a/R/pkg_ref_cache_dependencies.R b/R/pkg_ref_cache_dependencies.R new file mode 100644 index 00000000..0bb4dc0e --- /dev/null +++ b/R/pkg_ref_cache_dependencies.R @@ -0,0 +1,40 @@ +#' Cache package dependencies +#' +#' @inheritParams pkg_ref_cache +#' @family package reference cache +#' @return a \code{pkg_ref} object +#' @keywords internal +pkg_ref_cache.dependencies <- function(x, name, ...) { + UseMethod("pkg_ref_cache.dependencies") +} + + +pkg_ref_cache.dependencies.pkg_install <- function(x, name, ...) { + parse_dcf_dependencies(x$path) +} + +pkg_ref_cache.dependencies.pkg_source <- function (x, name, ...) { + parse_dcf_dependencies(x$path) +} + +pkg_ref_cache.dependencies.pkg_cran_remote <- function(x, name, ...){ + #Attempt to find CRAN URL by matching all urls returned by getOptions("repos") to memoise_cran_mirrors table + repos <- getOption("repos")[which(getOption("repos") %in% memoise_cran_mirrors()$URL)] + + if(length(repos)==0){ + repos <- grep("[\\.|//]cran\\.", getOption("repos"), ignore.case = T, value = T) + } + if(length(repos)==0){ + repos <- getOption("repos")[["CRAN"]] + } + + if(length(repos)==0){ + return(NA) + } else{ + get_package_dependencies(x$name, repo = repos[1]) ##Will use the first CRAN mirror found in the users environment + } +} + +pkg_ref_cache.dependencies.pkg_bioc_remote <- function(x, name, ...){ + get_package_dependencies(x$name, BiocManager::repositories()[1]) +} From aaa40c65a723d3b226bf22f0314bfe1d861270a8 Mon Sep 17 00:00:00 2001 From: Eric Milliman Date: Wed, 6 Apr 2022 17:10:43 -0400 Subject: [PATCH 18/50] new cohort assessment for dependency conflicts --- R/assess_has_dependency_conflict.R | 41 ++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 R/assess_has_dependency_conflict.R diff --git a/R/assess_has_dependency_conflict.R b/R/assess_has_dependency_conflict.R new file mode 100644 index 00000000..d6f9be83 --- /dev/null +++ b/R/assess_has_dependency_conflict.R @@ -0,0 +1,41 @@ +#' Assess a cohort for the presence of dependency conflicts +#' +#' @export +#' +assess_has_dependency_conflict <- function(x, ...){ + UseMethod("assess_has_dependency_conflict") +} +attributes(assess_dependencies)$column_name <- "dependency_conflict" +attributes(assess_dependencies)$label <- "Package dependency conflicts" + +#' @export +assess_has_dependency_conflict.cohort_ref <- function(x, ...){ + dep <- lapply(x$cohort, "[[", "dependencies") + nm <- unlist(lapply(x$cohort, "[", "name")) + + nm_lib <- as_tibble(x$library)[, c(1:2)] + + dep <- data.frame(ref=rep(nm, sapply(dep, nrow)), bind_rows(dep)) + dep$version <- str_extract(dep$package, "(?<=\\().+(?=\\))") + dep$version<- str_extract(dep$version, "\\d+\\.\\d+(\\.\\d+)*") + dep$package <- trimws(gsub("\\(.+\\)", "", dep$package)) + dep2 <- list(minVer = tapply(dep$version, dep$package, function(x) sort(x, decreasing = T)[1]), + minDep = tapply(dep$type, dep$package, function(x) sort(x)[1])) + dep2 <- merge(as.data.frame(dep2$minVer), as.data.frame(dep2$minDep), by="row.names") + + lib <- rbind(nm_lib, data.frame(package=nm, version=unlist(lapply(x$cohort, "[", "version")))) + dep3 <- merge(dep2, lib, by.x="Row.names", by.y="package", all.x = TRUE) + dep3$conflict <- apply(dep3, 1, function(x) { + if(is.na(x[4])){ + return(TRUE) + } else if(is.na(x[2]) & !is.na(x[4])){ + return(FALSE) + } else if (compareVersion(x[2],x[4])>0){ + return(TRUE) + } else { + return(FALSE) + } + }) + colnames(dep3) <- c("Pkg_dependency", "MinimumVersion","Type", "CurrentVersion", "IsConflict") + return(dep3[dep3$IsConflict, ]) +} From 2d912bf310a365ea63a1fb9d7b7e026856a20ead Mon Sep 17 00:00:00 2001 From: Eric Milliman Date: Mon, 11 Apr 2022 16:54:59 -0400 Subject: [PATCH 19/50] renamed "pkg" from copy pasta to "cohort" --- R/cohort_metric.R | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/R/cohort_metric.R b/R/cohort_metric.R index df417ca4..c9834e4c 100644 --- a/R/cohort_metric.R +++ b/R/cohort_metric.R @@ -15,7 +15,7 @@ cohort_metric <- function(x = NA, ..., class = c()) { #' Convert an object to a \code{cohort_metric} #' -#' @inheritParams pkg_metric +#' @inheritParams cohort_metric #' @return a \code{cohort_metric} object #' @export as_cohort_metric <- function(x, class = c()) { @@ -23,7 +23,6 @@ as_cohort_metric <- function(x, class = c()) { } - #' @export as_cohort_metric.default <- function(x, class = c()) { cohort_metric(x, class = class) @@ -53,8 +52,8 @@ as_cohort_metric.expr_output <- function(x, class = c()) { #' @keywords internal cohort_metric_eval <- function(expr, ..., class = c(), env = parent.frame()) { out <- capture_expr_output(substitute(expr), env = env, quoted = TRUE) - out_metric <- as_pkg_metric(out, class = class) - if (inherits(out, "error")) out_metric <- as_pkg_metric_error(out_metric) + out_metric <- as_cohort_metric(out, class = class) + if (inherits(out, "error")) out_metric <- as_cohort_metric(out_metric) out_metric } @@ -77,20 +76,20 @@ format.cohort_metric <- function(x, ...) { #' #' @param error an error condition object to capture #' -#' @return an error condition object after wrap \code{pkg_metric_error} class. +#' @return an error condition object after wrap \code{cohort_metric_error} class. #' @keywords internal as_cohort_metric_error <- function(error) { as_cohort_metric_condition(error, subclass = "cohort_metric_error") } -#' A pkg_metric subclass for general metric evaluation conditions +#' A cohort_metric subclass for general metric evaluation conditions #' -#' @param x an object to wrap in a \code{pkg_metric_condition} class +#' @param x an object to wrap in a \code{cohort_metric_condition} class #' @param ... additional arguments added as attributes to object \code{x} -#' @param subclass an optional subclass of \code{pkg_metric_condition} to +#' @param subclass an optional subclass of \code{cohort_metric_condition} to #' include #' -#' @return an object after wrap \code{pkg_metric_condition} class. +#' @return an object after wrap \code{cohort_metric_condition} class. #' @keywords internal as_cohort_metric_condition <- function(x, ..., subclass = c()) { dots <- list(...) From 7aec2876ffaa8ed5dd17426f3a0a67c39afc88d3 Mon Sep 17 00:00:00 2001 From: Eric Milliman Date: Tue, 12 Apr 2022 09:51:04 -0400 Subject: [PATCH 20/50] add cohort metric method. --- R/assess_has_dependency_conflict.R | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/R/assess_has_dependency_conflict.R b/R/assess_has_dependency_conflict.R index d6f9be83..11d1afdc 100644 --- a/R/assess_has_dependency_conflict.R +++ b/R/assess_has_dependency_conflict.R @@ -37,5 +37,18 @@ assess_has_dependency_conflict.cohort_ref <- function(x, ...){ } }) colnames(dep3) <- c("Pkg_dependency", "MinimumVersion","Type", "CurrentVersion", "IsConflict") - return(dep3[dep3$IsConflict, ]) + cohort_metric_eval(class= "cohort_metric_dependency_conflict", + dep3[dep3$IsConflict, ]) } + +#' Score a package for presence of dependency conflicts +#' +#' @return \code{1} if any dependencies are missing or conflicting, otherwise \code{0} +#' +#' @export +cohort_metric.cohort_metric_dependency_conflict <- function(x, ...) { + as.numeric(NROW(x) > 0) +} + +attributes(cohort_metric.cohort_metric_dependency_conflict)$label <- + "A binary indicator of whether the cohort has missing or conflicting dependencies." From 9d7d225dd10b110b75be503b888f033ddae64bc2 Mon Sep 17 00:00:00 2001 From: Eric Milliman Date: Tue, 12 Apr 2022 09:51:35 -0400 Subject: [PATCH 21/50] create aohort assessment dispatch function similar to pkg_assess --- R/cohort_assess.R | 66 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 R/cohort_assess.R diff --git a/R/cohort_assess.R b/R/cohort_assess.R new file mode 100644 index 00000000..28110250 --- /dev/null +++ b/R/cohort_assess.R @@ -0,0 +1,66 @@ +#' Apply assess_* family of functions to a cohort reference +#' +#' By default, use all \code{assess_*} functions in the \code{riskmetric} +#' namespace and produce a \code{\link[tibble]{tibble}} with one column per +#' assessment applied. +#' +#' @param x A single \code{\link{cohort_ref}} object or +#' \code{\link[tibble]{tibble}} of cohort references to assess +#' @param assessments A list of assessment functions to apply to each cohort +#' reference. By default, a list of all exported assess_* functions from the +#' riskmetric package. +#' @param ... additional arguments unused +#' @param error_handler A function, which accepts a single parameter expecting +#' the raised error, which will be called if any errors occur when attempting +#' to apply an assessment function. +#' +#' @return A \code{list_of_cohort_metric} object +#' +#' +#' +#' @importFrom tibble as_tibble +#' @importFrom vctrs new_list_of +#' @export +cohort_assess <- function(x, assessments = cohort_assessments(), ..., + error_handler = assessment_error_empty) { + UseMethod("cohort_assess") +} + +#' @export +cohort_assess.cohort_ref <- function(x, assessments = all_cohort_assessments(), ..., + error_handler = assessment_error_empty) { + + assessments <- use_assessments_column_names(assessments) + xout <- list() + + for (i in seq_along(assessments)) { + assessment_f <- assessments[[i]] + assessment_name <- names(assessments)[[i]] + + xout[[assessment_name]] <- tryCatch({ + assessment_f(x) + }, error = function(e) { + error_handler(e, x$name, assessment_name) + }) + + attributes(xout[[assessment_name]])$label <- attributes(assessment_f)$label + } + + vctrs::new_list_of(xout, + structure(logical(), class = "cohort_metric"), + class = "list_of_cohort_metric") +} + +#' A default list of assessments to perform for each package +#' +#' @return a list of assess_* functions exported from riskmetric +#' +#' @importFrom utils packageName +#' @export +all_cohort_assessments <- function() { + fs <- grep("^assess_.+cohort_ref$", + getNamespaceExports(utils::packageName()), + value = TRUE) + fs <- unique(gsub("\\..+", "", fs)) + Map(getExportedValue, fs, ns = list(utils::packageName())) +} From 732ce8f3e92a7cddeb810bd9351381fefd56e0b1 Mon Sep 17 00:00:00 2001 From: Eric Milliman Date: Tue, 12 Apr 2022 13:24:32 -0400 Subject: [PATCH 22/50] fixed return value of assess_namespace_export for cohort_ref --- R/assess_exported_namespace.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/assess_exported_namespace.R b/R/assess_exported_namespace.R index 6bd722c2..4ffa6a6d 100644 --- a/R/assess_exported_namespace.R +++ b/R/assess_exported_namespace.R @@ -39,7 +39,7 @@ assess_exported_namespace.pkg_source <- function(x, ...) { #' @export assess_exported_namespace.cohort_ref <- function(x, ...) { - ns <- lapply(x$cohort, assess_exported_namespace) + ns <- unlist(lapply(x$cohort, assess_exported_namespace)) } From bd32eb4da5491e124cabfb08a3a85479b326ac45 Mon Sep 17 00:00:00 2001 From: Eric Milliman Date: Tue, 12 Apr 2022 13:25:56 -0400 Subject: [PATCH 23/50] fixed return value of assess_reverse_dependencies for cohort_ref. added cohort_metric for assess_reverse_dependencies cohort_ref --- R/assess_reverse_dependencies.R | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/R/assess_reverse_dependencies.R b/R/assess_reverse_dependencies.R index 5048e17f..5a12c2f1 100644 --- a/R/assess_reverse_dependencies.R +++ b/R/assess_reverse_dependencies.R @@ -23,23 +23,24 @@ assess_reverse_dependencies.default <- function(x, ...){ #' @importFrom devtools revdep #' @export assess_reverse_dependencies.cohort_ref <- function(x, ...){ - #cohort_rev_deps <- devtools::revdep(x$cohort$name, bioconductor = TRUE) cohort_rev_deps <- lapply(x$cohort, assess_reverse_dependencies) + cohort_nm <- sapply(x$cohort, "[[", "name") + + cohort_rev_deps <- data.frame(pkg=rep(cohort_nm, sapply(cohort_rev_deps, length)), + revdep=unlist(cohort_rev_deps)) if(length(x$library)){ lib_pkgs <- sapply(x$library, function(x) x$name) } - return(lapply(cohort_rev_deps, function(x){ - pkg_metric_eval(class = "cohort_metric_reverse_dependencies", - x[x %in% lib_pkgs] + return(cohort_metric_eval(class = "cohort_metric_reverse_dependencies", + cohort_rev_deps[cohort_rev_deps$revdep %in% c(lib_pkgs, cohort_nm), ] ) - }) ) } attr(assess_reverse_dependencies, "column_name") <- "reverse_dependencies" -attr(assess_reverse_dependencies, "label") <- "List of reverse dependencies a package has" +attr(assess_reverse_dependencies, "label") <- "Table of reverse dependencies for each package." #' Scoring method for number of reverse dependencies a package has @@ -67,3 +68,14 @@ metric_score.pkg_metric_reverse_dependencies <- function(x,...){ attributes(metric_score.pkg_metric_reverse_dependencies)$label <- "The (log10) number of packages that depend on this package." + +#' Metric for the assessment of reverse dependencies of a cohort. +#' +#' @importFrom igraph fit_power_law +#' @export +cohort_metric.cohort_metric_reverse_dependencies <- function(x, ...){ + igraph::fit_power_law(tapply(cohort_rev_deps$revdep,cohort_rev_deps$pkg, length))$KS.p +} +attributes(cohort_metric.cohort_metric_reverse_dependencies)$label <- + "p-value of power law distribution fit" + From fddcf76087b633da852f3ee743bad0cf4252a54c Mon Sep 17 00:00:00 2001 From: Eric Milliman Date: Tue, 12 Apr 2022 13:26:27 -0400 Subject: [PATCH 24/50] namesspace and documentation update --- NAMESPACE | 12 +++++ man/all_cohort_assessments.Rd | 14 +++++ man/as_cohort_metric.Rd | 19 +++++++ man/as_cohort_metric_condition.Rd | 23 +++++++++ man/as_cohort_metric_error.Rd | 18 +++++++ man/assess_has_dependency_conflict.Rd | 11 ++++ man/cohort_assess.Rd | 35 +++++++++++++ man/cohort_metric.Rd | 23 +++++++++ ...etric.cohort_metric_dependency_conflict.Rd | 14 +++++ man/cohort_metric_eval.Rd | 26 ++++++++++ man/pkg_assess.Rd | 25 ++++----- man/pkg_ref_cache.archive_release_dates.Rd | 1 + man/pkg_ref_cache.bug_reports.Rd | 1 + man/pkg_ref_cache.bug_reports_host.Rd | 1 + man/pkg_ref_cache.bug_reports_url.Rd | 1 + man/pkg_ref_cache.covr_coverage.Rd | 1 + man/pkg_ref_cache.dependencies.Rd | 51 +++++++++++++++++++ man/pkg_ref_cache.description.Rd | 1 + man/pkg_ref_cache.downloads.Rd | 1 + man/pkg_ref_cache.expression_coverage.Rd | 1 + man/pkg_ref_cache.help.Rd | 1 + man/pkg_ref_cache.help_aliases.Rd | 1 + man/pkg_ref_cache.license.Rd | 1 + man/pkg_ref_cache.maintainer.Rd | 1 + man/pkg_ref_cache.news.Rd | 1 + man/pkg_ref_cache.news_urls.Rd | 1 + man/pkg_ref_cache.r_cmd_check.Rd | 1 + man/pkg_ref_cache.release_date.Rd | 1 + man/pkg_ref_cache.remote_checks.Rd | 1 + man/pkg_ref_cache.repo_base_url.Rd | 1 + man/pkg_ref_cache.source_control_url.Rd | 1 + man/pkg_ref_cache.tarball_url.Rd | 1 + man/pkg_ref_cache.vignettes.Rd | 1 + man/pkg_ref_cache.web_html.Rd | 1 + man/pkg_ref_cache.web_url.Rd | 1 + man/pkg_ref_cache.website_urls.Rd | 1 + man/riskmetric_metadata_caching.Rd | 1 + 37 files changed, 284 insertions(+), 12 deletions(-) create mode 100644 man/all_cohort_assessments.Rd create mode 100644 man/as_cohort_metric.Rd create mode 100644 man/as_cohort_metric_condition.Rd create mode 100644 man/as_cohort_metric_error.Rd create mode 100644 man/assess_has_dependency_conflict.Rd create mode 100644 man/cohort_assess.Rd create mode 100644 man/cohort_metric.Rd create mode 100644 man/cohort_metric.cohort_metric_dependency_conflict.Rd create mode 100644 man/cohort_metric_eval.Rd create mode 100644 man/pkg_ref_cache.dependencies.Rd diff --git a/NAMESPACE b/NAMESPACE index 53448ba0..258f7486 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -7,6 +7,8 @@ S3method("[<-",pkg_ref) S3method("[[",pkg_ref) S3method("[[<-",pkg_ref) S3method(.DollarNames,pkg_ref) +S3method(as_cohort_metric,default) +S3method(as_cohort_metric,expr_output) S3method(as_pkg_metric,default) S3method(as_pkg_metric,expr_output) S3method(as_pkg_ref,character) @@ -30,6 +32,7 @@ S3method(assess_exported_namespace,cohort_ref) S3method(assess_exported_namespace,default) S3method(assess_exported_namespace,pkg_install) S3method(assess_exported_namespace,pkg_source) +S3method(assess_has_dependency_conflict,cohort_ref) S3method(assess_has_news,pkg_ref) S3method(assess_has_vignettes,pkg_ref) S3method(assess_news_current,pkg_ref) @@ -43,6 +46,9 @@ S3method(assess_remote_checks,pkg_bioc_remote) S3method(assess_remote_checks,pkg_cran_remote) S3method(assess_reverse_dependencies,cohort_ref) S3method(assess_reverse_dependencies,default) +S3method(cohort_assess,cohort_ref) +S3method(format,cohort_metric) +S3method(format,cohort_metric_error) S3method(format,pkg_metric) S3method(format,pkg_metric_error) S3method(format,pkg_missing) @@ -85,6 +91,8 @@ S3method(vec_ptype_abbr,pkg_metric) S3method(vec_ptype_abbr,pkg_ref) S3method(with,pkg_ref) export(all_assessments) +export(all_cohort_assessments) +export(as_cohort_metric) export(as_list_of_pkg_ref) export(as_pkg_metric) export(as_pkg_ref) @@ -95,6 +103,7 @@ export(assess_export_help) export(assess_exported_namespace) export(assess_has_bug_reports_url) export(assess_has_bug_reports_url.pkg_ref) +export(assess_has_dependency_conflict) export(assess_has_maintainer) export(assess_has_news) export(assess_has_source_control) @@ -109,6 +118,9 @@ export(assess_reverse_dependencies) export(assessment_error_as_warning) export(assessment_error_empty) export(assessment_error_throw) +export(cohort_assess) +export(cohort_metric) +export(cohort_metric.cohort_metric_dependency_conflict) export(cohort_ref) export(get_assessments) export(metric_score) diff --git a/man/all_cohort_assessments.Rd b/man/all_cohort_assessments.Rd new file mode 100644 index 00000000..b47cfe55 --- /dev/null +++ b/man/all_cohort_assessments.Rd @@ -0,0 +1,14 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/cohort_assess.R +\name{all_cohort_assessments} +\alias{all_cohort_assessments} +\title{A default list of assessments to perform for each package} +\usage{ +all_cohort_assessments() +} +\value{ +a list of assess_* functions exported from riskmetric +} +\description{ +A default list of assessments to perform for each package +} diff --git a/man/as_cohort_metric.Rd b/man/as_cohort_metric.Rd new file mode 100644 index 00000000..7f11fefd --- /dev/null +++ b/man/as_cohort_metric.Rd @@ -0,0 +1,19 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/cohort_metric.R +\name{as_cohort_metric} +\alias{as_cohort_metric} +\title{Convert an object to a \code{cohort_metric}} +\usage{ +as_cohort_metric(x, class = c()) +} +\arguments{ +\item{x}{data to store as a \code{cohort_metric}} + +\item{class}{a subclass to differentiate the \code{cohort_metric} object} +} +\value{ +a \code{cohort_metric} object +} +\description{ +Convert an object to a \code{cohort_metric} +} diff --git a/man/as_cohort_metric_condition.Rd b/man/as_cohort_metric_condition.Rd new file mode 100644 index 00000000..e5336ba5 --- /dev/null +++ b/man/as_cohort_metric_condition.Rd @@ -0,0 +1,23 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/cohort_metric.R +\name{as_cohort_metric_condition} +\alias{as_cohort_metric_condition} +\title{A cohort_metric subclass for general metric evaluation conditions} +\usage{ +as_cohort_metric_condition(x, ..., subclass = c()) +} +\arguments{ +\item{x}{an object to wrap in a \code{cohort_metric_condition} class} + +\item{...}{additional arguments added as attributes to object \code{x}} + +\item{subclass}{an optional subclass of \code{cohort_metric_condition} to +include} +} +\value{ +an object after wrap \code{cohort_metric_condition} class. +} +\description{ +A cohort_metric subclass for general metric evaluation conditions +} +\keyword{internal} diff --git a/man/as_cohort_metric_error.Rd b/man/as_cohort_metric_error.Rd new file mode 100644 index 00000000..60e1fdaa --- /dev/null +++ b/man/as_cohort_metric_error.Rd @@ -0,0 +1,18 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/cohort_metric.R +\name{as_cohort_metric_error} +\alias{as_cohort_metric_error} +\title{A subclass wrapping an error with an additional parent class} +\usage{ +as_cohort_metric_error(error) +} +\arguments{ +\item{error}{an error condition object to capture} +} +\value{ +an error condition object after wrap \code{cohort_metric_error} class. +} +\description{ +A subclass wrapping an error with an additional parent class +} +\keyword{internal} diff --git a/man/assess_has_dependency_conflict.Rd b/man/assess_has_dependency_conflict.Rd new file mode 100644 index 00000000..98b9927b --- /dev/null +++ b/man/assess_has_dependency_conflict.Rd @@ -0,0 +1,11 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/assess_has_dependency_conflict.R +\name{assess_has_dependency_conflict} +\alias{assess_has_dependency_conflict} +\title{Assess a cohort for the presence of dependency conflicts} +\usage{ +assess_has_dependency_conflict(x, ...) +} +\description{ +Assess a cohort for the presence of dependency conflicts +} diff --git a/man/cohort_assess.Rd b/man/cohort_assess.Rd new file mode 100644 index 00000000..54878365 --- /dev/null +++ b/man/cohort_assess.Rd @@ -0,0 +1,35 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/cohort_assess.R +\name{cohort_assess} +\alias{cohort_assess} +\title{Apply assess_* family of functions to a cohort reference} +\usage{ +cohort_assess( + x, + assessments = cohort_assessments(), + ..., + error_handler = assessment_error_empty +) +} +\arguments{ +\item{x}{A single \code{\link{cohort_ref}} object or +\code{\link[tibble]{tibble}} of cohort references to assess} + +\item{assessments}{A list of assessment functions to apply to each cohort +reference. By default, a list of all exported assess_* functions from the +riskmetric package.} + +\item{...}{additional arguments unused} + +\item{error_handler}{A function, which accepts a single parameter expecting +the raised error, which will be called if any errors occur when attempting +to apply an assessment function.} +} +\value{ +A \code{list_of_cohort_metric} object +} +\description{ +By default, use all \code{assess_*} functions in the \code{riskmetric} +namespace and produce a \code{\link[tibble]{tibble}} with one column per +assessment applied. +} diff --git a/man/cohort_metric.Rd b/man/cohort_metric.Rd new file mode 100644 index 00000000..a98b087c --- /dev/null +++ b/man/cohort_metric.Rd @@ -0,0 +1,23 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/cohort_metric.R +\name{cohort_metric} +\alias{cohort_metric} +\title{A helper for structuring assessment return objects for dispatch with the +score function} +\usage{ +cohort_metric(x = NA, ..., class = c()) +} +\arguments{ +\item{x}{data to store as a \code{cohort_metric}} + +\item{...}{additional attributes to bind to the \code{cohort_metric} object} + +\item{class}{a subclass to differentiate the \code{cohort_metric} object} +} +\value{ +a \code{cohort_metric} object +} +\description{ +A helper for structuring assessment return objects for dispatch with the +score function +} diff --git a/man/cohort_metric.cohort_metric_dependency_conflict.Rd b/man/cohort_metric.cohort_metric_dependency_conflict.Rd new file mode 100644 index 00000000..189cbb5c --- /dev/null +++ b/man/cohort_metric.cohort_metric_dependency_conflict.Rd @@ -0,0 +1,14 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/assess_has_dependency_conflict.R +\name{cohort_metric.cohort_metric_dependency_conflict} +\alias{cohort_metric.cohort_metric_dependency_conflict} +\title{Score a package for presence of dependency conflicts} +\usage{ +cohort_metric.cohort_metric_dependency_conflict(x, ...) +} +\value{ +\code{1} if any dependencies are missing or conflicting, otherwise \code{0} +} +\description{ +Score a package for presence of dependency conflicts +} diff --git a/man/cohort_metric_eval.Rd b/man/cohort_metric_eval.Rd new file mode 100644 index 00000000..2945e6cb --- /dev/null +++ b/man/cohort_metric_eval.Rd @@ -0,0 +1,26 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/cohort_metric.R +\name{cohort_metric_eval} +\alias{cohort_metric_eval} +\title{Evaluate a cohort metric} +\usage{ +cohort_metric_eval(expr, ..., class = c(), env = parent.frame()) +} +\arguments{ +\item{expr}{An expression to evaluate in order to calculate a +\code{cohort_metric}} + +\item{...}{additional attributes to bind to the \code{cohort_metric} object} + +\item{class}{a subclass to differentiate the \code{cohort_metric} object} + +\item{env}{An environment in which \code{expr} is to be evaluated} +} +\value{ +a \code{cohort_metric} object containing the result of \code{expr} +} +\description{ +Evalute code relevant to a cohort metric, capturing the evaluated code as well as +any messages, warnings or errors that are thrown in the process. +} +\keyword{internal} diff --git a/man/pkg_assess.Rd b/man/pkg_assess.Rd index 2da1a43d..ff53fb5f 100644 --- a/man/pkg_assess.Rd +++ b/man/pkg_assess.Rd @@ -43,23 +43,24 @@ assessment applied. \section{Assessment function catalog}{ \describe{ -\item{\code{\link{assess_dependencies}}}{Package dependency footprint} -\item{\code{\link{assess_remote_checks}}}{Number of OS flavors that passed/warned/errored on R CMD check} -\item{\code{\link{assess_has_news}}}{number of discovered NEWS files} \item{\code{\link{assess_last_30_bugs_status}}}{vector indicating whether BugReports status is closed} -\item{\code{\link{assess_export_help}}}{exported objects have documentation} +\item{\code{\link{assess_license}}}{software is released with an acceptable license} \item{\code{\link{assess_downloads_1yr}}}{number of downloads in the past year} +\item{\code{\link{assess_has_dependency_conflict}}}{assess_has_dependency_conflict} +\item{\code{\link{assess_exported_namespace}}}{Objects exported by package} \item{\code{\link{assess_has_website}}}{a vector of associated website urls} -\item{\code{\link{assess_has_source_control}}}{a vector of associated source control urls} -\item{\code{\link{assess_license}}}{software is released with an acceptable license} \item{\code{\link{assess_news_current}}}{NEWS file contains entry for current version number} -\item{\code{\link{assess_covr_coverage}}}{Package unit test coverage} -\item{\code{\link{assess_r_cmd_check}}}{Package check results} -\item{\code{\link{assess_exported_namespace}}}{Objects exported by package} -\item{\code{\link{assess_has_maintainer}}}{a vector of associated maintainers} -\item{\code{\link{assess_has_vignettes}}}{number of discovered vignettes files} -\item{\code{\link{assess_has_bug_reports_url}}}{presence of a bug reports url in repository} +\item{\code{\link{assess_export_help}}}{exported objects have documentation} \item{\code{\link{assess_reverse_dependencies}}}{List of reverse dependencies a package has} +\item{\code{\link{assess_has_bug_reports_url}}}{presence of a bug reports url in repository} +\item{\code{\link{assess_has_source_control}}}{a vector of associated source control urls} +\item{\code{\link{assess_dependencies}}}{Package dependency conflicts} +\item{\code{\link{assess_has_vignettes}}}{number of discovered vignettes files} +\item{\code{\link{assess_has_maintainer}}}{a vector of associated maintainers} +\item{\code{\link{assess_r_cmd_check}}}{Package check results} +\item{\code{\link{assess_covr_coverage}}}{Package unit test coverage} +\item{\code{\link{assess_remote_checks}}}{Number of OS flavors that passed/warned/errored on R CMD check} +\item{\code{\link{assess_has_news}}}{number of discovered NEWS files} } } diff --git a/man/pkg_ref_cache.archive_release_dates.Rd b/man/pkg_ref_cache.archive_release_dates.Rd index a46f21b2..f16e3ba4 100644 --- a/man/pkg_ref_cache.archive_release_dates.Rd +++ b/man/pkg_ref_cache.archive_release_dates.Rd @@ -25,6 +25,7 @@ Other package reference cache: \code{\link{pkg_ref_cache.bug_reports_url}()}, \code{\link{pkg_ref_cache.bug_reports}()}, \code{\link{pkg_ref_cache.covr_coverage}()}, +\code{\link{pkg_ref_cache.dependencies}()}, \code{\link{pkg_ref_cache.description}()}, \code{\link{pkg_ref_cache.downloads}()}, \code{\link{pkg_ref_cache.expression_coverage}()}, diff --git a/man/pkg_ref_cache.bug_reports.Rd b/man/pkg_ref_cache.bug_reports.Rd index b5ab0869..d9aa595f 100644 --- a/man/pkg_ref_cache.bug_reports.Rd +++ b/man/pkg_ref_cache.bug_reports.Rd @@ -23,6 +23,7 @@ Other package reference cache: \code{\link{pkg_ref_cache.bug_reports_host}()}, \code{\link{pkg_ref_cache.bug_reports_url}()}, \code{\link{pkg_ref_cache.covr_coverage}()}, +\code{\link{pkg_ref_cache.dependencies}()}, \code{\link{pkg_ref_cache.description}()}, \code{\link{pkg_ref_cache.downloads}()}, \code{\link{pkg_ref_cache.expression_coverage}()}, diff --git a/man/pkg_ref_cache.bug_reports_host.Rd b/man/pkg_ref_cache.bug_reports_host.Rd index 822277e9..ab5e7641 100644 --- a/man/pkg_ref_cache.bug_reports_host.Rd +++ b/man/pkg_ref_cache.bug_reports_host.Rd @@ -23,6 +23,7 @@ Other package reference cache: \code{\link{pkg_ref_cache.bug_reports_url}()}, \code{\link{pkg_ref_cache.bug_reports}()}, \code{\link{pkg_ref_cache.covr_coverage}()}, +\code{\link{pkg_ref_cache.dependencies}()}, \code{\link{pkg_ref_cache.description}()}, \code{\link{pkg_ref_cache.downloads}()}, \code{\link{pkg_ref_cache.expression_coverage}()}, diff --git a/man/pkg_ref_cache.bug_reports_url.Rd b/man/pkg_ref_cache.bug_reports_url.Rd index f79e1aca..aa089f03 100644 --- a/man/pkg_ref_cache.bug_reports_url.Rd +++ b/man/pkg_ref_cache.bug_reports_url.Rd @@ -23,6 +23,7 @@ Other package reference cache: \code{\link{pkg_ref_cache.bug_reports_host}()}, \code{\link{pkg_ref_cache.bug_reports}()}, \code{\link{pkg_ref_cache.covr_coverage}()}, +\code{\link{pkg_ref_cache.dependencies}()}, \code{\link{pkg_ref_cache.description}()}, \code{\link{pkg_ref_cache.downloads}()}, \code{\link{pkg_ref_cache.expression_coverage}()}, diff --git a/man/pkg_ref_cache.covr_coverage.Rd b/man/pkg_ref_cache.covr_coverage.Rd index ab46d5c0..14883ccf 100644 --- a/man/pkg_ref_cache.covr_coverage.Rd +++ b/man/pkg_ref_cache.covr_coverage.Rd @@ -23,6 +23,7 @@ Other package reference cache: \code{\link{pkg_ref_cache.bug_reports_host}()}, \code{\link{pkg_ref_cache.bug_reports_url}()}, \code{\link{pkg_ref_cache.bug_reports}()}, +\code{\link{pkg_ref_cache.dependencies}()}, \code{\link{pkg_ref_cache.description}()}, \code{\link{pkg_ref_cache.downloads}()}, \code{\link{pkg_ref_cache.expression_coverage}()}, diff --git a/man/pkg_ref_cache.dependencies.Rd b/man/pkg_ref_cache.dependencies.Rd new file mode 100644 index 00000000..30fef851 --- /dev/null +++ b/man/pkg_ref_cache.dependencies.Rd @@ -0,0 +1,51 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/pkg_ref_cache_dependencies.R +\name{pkg_ref_cache.dependencies} +\alias{pkg_ref_cache.dependencies} +\title{Cache package dependencies} +\usage{ +pkg_ref_cache.dependencies(x, name, ...) +} +\arguments{ +\item{x}{a package reference object} + +\item{name}{the name of the field that needs to be cached} + +\item{...}{additional arguments used for computing cached values} +} +\value{ +a \code{pkg_ref} object +} +\description{ +Cache package dependencies +} +\seealso{ +Other package reference cache: +\code{\link{pkg_ref_cache.archive_release_dates}()}, +\code{\link{pkg_ref_cache.bug_reports_host}()}, +\code{\link{pkg_ref_cache.bug_reports_url}()}, +\code{\link{pkg_ref_cache.bug_reports}()}, +\code{\link{pkg_ref_cache.covr_coverage}()}, +\code{\link{pkg_ref_cache.description}()}, +\code{\link{pkg_ref_cache.downloads}()}, +\code{\link{pkg_ref_cache.expression_coverage}()}, +\code{\link{pkg_ref_cache.help_aliases}()}, +\code{\link{pkg_ref_cache.help}()}, +\code{\link{pkg_ref_cache.license}()}, +\code{\link{pkg_ref_cache.maintainer}()}, +\code{\link{pkg_ref_cache.news_urls}()}, +\code{\link{pkg_ref_cache.news}()}, +\code{\link{pkg_ref_cache.r_cmd_check}()}, +\code{\link{pkg_ref_cache.release_date}()}, +\code{\link{pkg_ref_cache.remote_checks}()}, +\code{\link{pkg_ref_cache.repo_base_url}()}, +\code{\link{pkg_ref_cache.source_control_url}()}, +\code{\link{pkg_ref_cache.tarball_url}()}, +\code{\link{pkg_ref_cache.vignettes}()}, +\code{\link{pkg_ref_cache.web_html}()}, +\code{\link{pkg_ref_cache.web_url}()}, +\code{\link{pkg_ref_cache.website_urls}()}, +\code{\link{pkg_ref_cache}()} +} +\concept{package reference cache} +\keyword{internal} diff --git a/man/pkg_ref_cache.description.Rd b/man/pkg_ref_cache.description.Rd index 7854a531..9aa67f56 100644 --- a/man/pkg_ref_cache.description.Rd +++ b/man/pkg_ref_cache.description.Rd @@ -26,6 +26,7 @@ Other package reference cache: \code{\link{pkg_ref_cache.bug_reports_url}()}, \code{\link{pkg_ref_cache.bug_reports}()}, \code{\link{pkg_ref_cache.covr_coverage}()}, +\code{\link{pkg_ref_cache.dependencies}()}, \code{\link{pkg_ref_cache.downloads}()}, \code{\link{pkg_ref_cache.expression_coverage}()}, \code{\link{pkg_ref_cache.help_aliases}()}, diff --git a/man/pkg_ref_cache.downloads.Rd b/man/pkg_ref_cache.downloads.Rd index 0618b73c..7af50de2 100644 --- a/man/pkg_ref_cache.downloads.Rd +++ b/man/pkg_ref_cache.downloads.Rd @@ -24,6 +24,7 @@ Other package reference cache: \code{\link{pkg_ref_cache.bug_reports_url}()}, \code{\link{pkg_ref_cache.bug_reports}()}, \code{\link{pkg_ref_cache.covr_coverage}()}, +\code{\link{pkg_ref_cache.dependencies}()}, \code{\link{pkg_ref_cache.description}()}, \code{\link{pkg_ref_cache.expression_coverage}()}, \code{\link{pkg_ref_cache.help_aliases}()}, diff --git a/man/pkg_ref_cache.expression_coverage.Rd b/man/pkg_ref_cache.expression_coverage.Rd index e0b0be01..61799d4f 100644 --- a/man/pkg_ref_cache.expression_coverage.Rd +++ b/man/pkg_ref_cache.expression_coverage.Rd @@ -24,6 +24,7 @@ Other package reference cache: \code{\link{pkg_ref_cache.bug_reports_url}()}, \code{\link{pkg_ref_cache.bug_reports}()}, \code{\link{pkg_ref_cache.covr_coverage}()}, +\code{\link{pkg_ref_cache.dependencies}()}, \code{\link{pkg_ref_cache.description}()}, \code{\link{pkg_ref_cache.downloads}()}, \code{\link{pkg_ref_cache.help_aliases}()}, diff --git a/man/pkg_ref_cache.help.Rd b/man/pkg_ref_cache.help.Rd index fa18398a..d91615d7 100644 --- a/man/pkg_ref_cache.help.Rd +++ b/man/pkg_ref_cache.help.Rd @@ -26,6 +26,7 @@ Other package reference cache: \code{\link{pkg_ref_cache.bug_reports_url}()}, \code{\link{pkg_ref_cache.bug_reports}()}, \code{\link{pkg_ref_cache.covr_coverage}()}, +\code{\link{pkg_ref_cache.dependencies}()}, \code{\link{pkg_ref_cache.description}()}, \code{\link{pkg_ref_cache.downloads}()}, \code{\link{pkg_ref_cache.expression_coverage}()}, diff --git a/man/pkg_ref_cache.help_aliases.Rd b/man/pkg_ref_cache.help_aliases.Rd index c8cbc430..d5948bfd 100644 --- a/man/pkg_ref_cache.help_aliases.Rd +++ b/man/pkg_ref_cache.help_aliases.Rd @@ -26,6 +26,7 @@ Other package reference cache: \code{\link{pkg_ref_cache.bug_reports_url}()}, \code{\link{pkg_ref_cache.bug_reports}()}, \code{\link{pkg_ref_cache.covr_coverage}()}, +\code{\link{pkg_ref_cache.dependencies}()}, \code{\link{pkg_ref_cache.description}()}, \code{\link{pkg_ref_cache.downloads}()}, \code{\link{pkg_ref_cache.expression_coverage}()}, diff --git a/man/pkg_ref_cache.license.Rd b/man/pkg_ref_cache.license.Rd index 258b24ae..6258d8b6 100644 --- a/man/pkg_ref_cache.license.Rd +++ b/man/pkg_ref_cache.license.Rd @@ -24,6 +24,7 @@ Other package reference cache: \code{\link{pkg_ref_cache.bug_reports_url}()}, \code{\link{pkg_ref_cache.bug_reports}()}, \code{\link{pkg_ref_cache.covr_coverage}()}, +\code{\link{pkg_ref_cache.dependencies}()}, \code{\link{pkg_ref_cache.description}()}, \code{\link{pkg_ref_cache.downloads}()}, \code{\link{pkg_ref_cache.expression_coverage}()}, diff --git a/man/pkg_ref_cache.maintainer.Rd b/man/pkg_ref_cache.maintainer.Rd index 7b8fde0b..c115b620 100644 --- a/man/pkg_ref_cache.maintainer.Rd +++ b/man/pkg_ref_cache.maintainer.Rd @@ -26,6 +26,7 @@ Other package reference cache: \code{\link{pkg_ref_cache.bug_reports_url}()}, \code{\link{pkg_ref_cache.bug_reports}()}, \code{\link{pkg_ref_cache.covr_coverage}()}, +\code{\link{pkg_ref_cache.dependencies}()}, \code{\link{pkg_ref_cache.description}()}, \code{\link{pkg_ref_cache.downloads}()}, \code{\link{pkg_ref_cache.expression_coverage}()}, diff --git a/man/pkg_ref_cache.news.Rd b/man/pkg_ref_cache.news.Rd index 74a1023c..65cf8719 100644 --- a/man/pkg_ref_cache.news.Rd +++ b/man/pkg_ref_cache.news.Rd @@ -26,6 +26,7 @@ Other package reference cache: \code{\link{pkg_ref_cache.bug_reports_url}()}, \code{\link{pkg_ref_cache.bug_reports}()}, \code{\link{pkg_ref_cache.covr_coverage}()}, +\code{\link{pkg_ref_cache.dependencies}()}, \code{\link{pkg_ref_cache.description}()}, \code{\link{pkg_ref_cache.downloads}()}, \code{\link{pkg_ref_cache.expression_coverage}()}, diff --git a/man/pkg_ref_cache.news_urls.Rd b/man/pkg_ref_cache.news_urls.Rd index 3f1e333b..ae9e151c 100644 --- a/man/pkg_ref_cache.news_urls.Rd +++ b/man/pkg_ref_cache.news_urls.Rd @@ -26,6 +26,7 @@ Other package reference cache: \code{\link{pkg_ref_cache.bug_reports_url}()}, \code{\link{pkg_ref_cache.bug_reports}()}, \code{\link{pkg_ref_cache.covr_coverage}()}, +\code{\link{pkg_ref_cache.dependencies}()}, \code{\link{pkg_ref_cache.description}()}, \code{\link{pkg_ref_cache.downloads}()}, \code{\link{pkg_ref_cache.expression_coverage}()}, diff --git a/man/pkg_ref_cache.r_cmd_check.Rd b/man/pkg_ref_cache.r_cmd_check.Rd index d9ab95a8..9c36777a 100644 --- a/man/pkg_ref_cache.r_cmd_check.Rd +++ b/man/pkg_ref_cache.r_cmd_check.Rd @@ -24,6 +24,7 @@ Other package reference cache: \code{\link{pkg_ref_cache.bug_reports_url}()}, \code{\link{pkg_ref_cache.bug_reports}()}, \code{\link{pkg_ref_cache.covr_coverage}()}, +\code{\link{pkg_ref_cache.dependencies}()}, \code{\link{pkg_ref_cache.description}()}, \code{\link{pkg_ref_cache.downloads}()}, \code{\link{pkg_ref_cache.expression_coverage}()}, diff --git a/man/pkg_ref_cache.release_date.Rd b/man/pkg_ref_cache.release_date.Rd index f3c7fd9d..5f8e5aaf 100644 --- a/man/pkg_ref_cache.release_date.Rd +++ b/man/pkg_ref_cache.release_date.Rd @@ -26,6 +26,7 @@ Other package reference cache: \code{\link{pkg_ref_cache.bug_reports_url}()}, \code{\link{pkg_ref_cache.bug_reports}()}, \code{\link{pkg_ref_cache.covr_coverage}()}, +\code{\link{pkg_ref_cache.dependencies}()}, \code{\link{pkg_ref_cache.description}()}, \code{\link{pkg_ref_cache.downloads}()}, \code{\link{pkg_ref_cache.expression_coverage}()}, diff --git a/man/pkg_ref_cache.remote_checks.Rd b/man/pkg_ref_cache.remote_checks.Rd index 11757231..8741b185 100644 --- a/man/pkg_ref_cache.remote_checks.Rd +++ b/man/pkg_ref_cache.remote_checks.Rd @@ -24,6 +24,7 @@ Other package reference cache: \code{\link{pkg_ref_cache.bug_reports_url}()}, \code{\link{pkg_ref_cache.bug_reports}()}, \code{\link{pkg_ref_cache.covr_coverage}()}, +\code{\link{pkg_ref_cache.dependencies}()}, \code{\link{pkg_ref_cache.description}()}, \code{\link{pkg_ref_cache.downloads}()}, \code{\link{pkg_ref_cache.expression_coverage}()}, diff --git a/man/pkg_ref_cache.repo_base_url.Rd b/man/pkg_ref_cache.repo_base_url.Rd index 3158db65..45b11c9f 100644 --- a/man/pkg_ref_cache.repo_base_url.Rd +++ b/man/pkg_ref_cache.repo_base_url.Rd @@ -26,6 +26,7 @@ Other package reference cache: \code{\link{pkg_ref_cache.bug_reports_url}()}, \code{\link{pkg_ref_cache.bug_reports}()}, \code{\link{pkg_ref_cache.covr_coverage}()}, +\code{\link{pkg_ref_cache.dependencies}()}, \code{\link{pkg_ref_cache.description}()}, \code{\link{pkg_ref_cache.downloads}()}, \code{\link{pkg_ref_cache.expression_coverage}()}, diff --git a/man/pkg_ref_cache.source_control_url.Rd b/man/pkg_ref_cache.source_control_url.Rd index 1c7768fe..7186437f 100644 --- a/man/pkg_ref_cache.source_control_url.Rd +++ b/man/pkg_ref_cache.source_control_url.Rd @@ -26,6 +26,7 @@ Other package reference cache: \code{\link{pkg_ref_cache.bug_reports_url}()}, \code{\link{pkg_ref_cache.bug_reports}()}, \code{\link{pkg_ref_cache.covr_coverage}()}, +\code{\link{pkg_ref_cache.dependencies}()}, \code{\link{pkg_ref_cache.description}()}, \code{\link{pkg_ref_cache.downloads}()}, \code{\link{pkg_ref_cache.expression_coverage}()}, diff --git a/man/pkg_ref_cache.tarball_url.Rd b/man/pkg_ref_cache.tarball_url.Rd index b7e77e18..a469aa86 100644 --- a/man/pkg_ref_cache.tarball_url.Rd +++ b/man/pkg_ref_cache.tarball_url.Rd @@ -26,6 +26,7 @@ Other package reference cache: \code{\link{pkg_ref_cache.bug_reports_url}()}, \code{\link{pkg_ref_cache.bug_reports}()}, \code{\link{pkg_ref_cache.covr_coverage}()}, +\code{\link{pkg_ref_cache.dependencies}()}, \code{\link{pkg_ref_cache.description}()}, \code{\link{pkg_ref_cache.downloads}()}, \code{\link{pkg_ref_cache.expression_coverage}()}, diff --git a/man/pkg_ref_cache.vignettes.Rd b/man/pkg_ref_cache.vignettes.Rd index 80490d53..6ba21f53 100644 --- a/man/pkg_ref_cache.vignettes.Rd +++ b/man/pkg_ref_cache.vignettes.Rd @@ -26,6 +26,7 @@ Other package reference cache: \code{\link{pkg_ref_cache.bug_reports_url}()}, \code{\link{pkg_ref_cache.bug_reports}()}, \code{\link{pkg_ref_cache.covr_coverage}()}, +\code{\link{pkg_ref_cache.dependencies}()}, \code{\link{pkg_ref_cache.description}()}, \code{\link{pkg_ref_cache.downloads}()}, \code{\link{pkg_ref_cache.expression_coverage}()}, diff --git a/man/pkg_ref_cache.web_html.Rd b/man/pkg_ref_cache.web_html.Rd index df5da0b3..9816e48a 100644 --- a/man/pkg_ref_cache.web_html.Rd +++ b/man/pkg_ref_cache.web_html.Rd @@ -26,6 +26,7 @@ Other package reference cache: \code{\link{pkg_ref_cache.bug_reports_url}()}, \code{\link{pkg_ref_cache.bug_reports}()}, \code{\link{pkg_ref_cache.covr_coverage}()}, +\code{\link{pkg_ref_cache.dependencies}()}, \code{\link{pkg_ref_cache.description}()}, \code{\link{pkg_ref_cache.downloads}()}, \code{\link{pkg_ref_cache.expression_coverage}()}, diff --git a/man/pkg_ref_cache.web_url.Rd b/man/pkg_ref_cache.web_url.Rd index 31d97d33..92d92347 100644 --- a/man/pkg_ref_cache.web_url.Rd +++ b/man/pkg_ref_cache.web_url.Rd @@ -26,6 +26,7 @@ Other package reference cache: \code{\link{pkg_ref_cache.bug_reports_url}()}, \code{\link{pkg_ref_cache.bug_reports}()}, \code{\link{pkg_ref_cache.covr_coverage}()}, +\code{\link{pkg_ref_cache.dependencies}()}, \code{\link{pkg_ref_cache.description}()}, \code{\link{pkg_ref_cache.downloads}()}, \code{\link{pkg_ref_cache.expression_coverage}()}, diff --git a/man/pkg_ref_cache.website_urls.Rd b/man/pkg_ref_cache.website_urls.Rd index af8e3ef6..873d998a 100644 --- a/man/pkg_ref_cache.website_urls.Rd +++ b/man/pkg_ref_cache.website_urls.Rd @@ -26,6 +26,7 @@ Other package reference cache: \code{\link{pkg_ref_cache.bug_reports_url}()}, \code{\link{pkg_ref_cache.bug_reports}()}, \code{\link{pkg_ref_cache.covr_coverage}()}, +\code{\link{pkg_ref_cache.dependencies}()}, \code{\link{pkg_ref_cache.description}()}, \code{\link{pkg_ref_cache.downloads}()}, \code{\link{pkg_ref_cache.expression_coverage}()}, diff --git a/man/riskmetric_metadata_caching.Rd b/man/riskmetric_metadata_caching.Rd index d692a194..522ad13e 100644 --- a/man/riskmetric_metadata_caching.Rd +++ b/man/riskmetric_metadata_caching.Rd @@ -107,6 +107,7 @@ Other package reference cache: \code{\link{pkg_ref_cache.bug_reports_url}()}, \code{\link{pkg_ref_cache.bug_reports}()}, \code{\link{pkg_ref_cache.covr_coverage}()}, +\code{\link{pkg_ref_cache.dependencies}()}, \code{\link{pkg_ref_cache.description}()}, \code{\link{pkg_ref_cache.downloads}()}, \code{\link{pkg_ref_cache.expression_coverage}()}, From 1bf7bea23aaafa43c3b01fc0e850a5bee5fe663b Mon Sep 17 00:00:00 2001 From: Eric Milliman Date: Tue, 12 Apr 2022 16:11:04 -0400 Subject: [PATCH 25/50] documentation update --- NAMESPACE | 6 +++++- man/cohort_score.Rd | 15 +++++++++++++++ ...ic_score.cohort_metric_dependency_conflict.Rd} | 6 +++--- ...ic_score.cohort_metric_reverse_dependencies.Rd | 11 +++++++++++ man/pkg_assess.Rd | 2 +- 5 files changed, 35 insertions(+), 5 deletions(-) create mode 100644 man/cohort_score.Rd rename man/{cohort_metric.cohort_metric_dependency_conflict.Rd => metric_score.cohort_metric_dependency_conflict.Rd} (65%) create mode 100644 man/metric_score.cohort_metric_reverse_dependencies.Rd diff --git a/NAMESPACE b/NAMESPACE index 258f7486..32b5a5c8 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -47,12 +47,15 @@ S3method(assess_remote_checks,pkg_cran_remote) S3method(assess_reverse_dependencies,cohort_ref) S3method(assess_reverse_dependencies,default) S3method(cohort_assess,cohort_ref) +S3method(cohort_score,list_of_cohort_metric) S3method(format,cohort_metric) S3method(format,cohort_metric_error) S3method(format,pkg_metric) S3method(format,pkg_metric_error) S3method(format,pkg_missing) S3method(format,pkg_ref) +S3method(metric_score,cohort_metric_dependency_conflict) +S3method(metric_score,cohort_metric_reverse_dependencies) S3method(metric_score,default) S3method(metric_score,pkg_metric_covr_coverage) S3method(metric_score,pkg_metric_dependencies) @@ -120,8 +123,8 @@ export(assessment_error_empty) export(assessment_error_throw) export(cohort_assess) export(cohort_metric) -export(cohort_metric.cohort_metric_dependency_conflict) export(cohort_ref) +export(cohort_score) export(get_assessments) export(metric_score) export(new_list_of_pkg_ref) @@ -147,6 +150,7 @@ importFrom(devtools,revdep) importFrom(dplyr,bind_rows) importFrom(httr,GET) importFrom(httr,content) +importFrom(igraph,fit_power_law) importFrom(memoise,memoise) importFrom(pillar,new_pillar_shaft_simple) importFrom(pillar,pillar_shaft) diff --git a/man/cohort_score.Rd b/man/cohort_score.Rd new file mode 100644 index 00000000..ef169bc2 --- /dev/null +++ b/man/cohort_score.Rd @@ -0,0 +1,15 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/cohort_score.R +\name{cohort_score} +\alias{cohort_score} +\title{Score a cohort assessment, collapsing results into a single numeric +cohort_score() calculates the risk involved with using a cohort of packages. Risk ranges +from 0 (low-risk) to 1 (high-risk).} +\usage{ +cohort_score(x, ..., error_handler = score_error_default) +} +\description{ +Score a cohort assessment, collapsing results into a single numeric +cohort_score() calculates the risk involved with using a cohort of packages. Risk ranges +from 0 (low-risk) to 1 (high-risk). +} diff --git a/man/cohort_metric.cohort_metric_dependency_conflict.Rd b/man/metric_score.cohort_metric_dependency_conflict.Rd similarity index 65% rename from man/cohort_metric.cohort_metric_dependency_conflict.Rd rename to man/metric_score.cohort_metric_dependency_conflict.Rd index 189cbb5c..aad71bef 100644 --- a/man/cohort_metric.cohort_metric_dependency_conflict.Rd +++ b/man/metric_score.cohort_metric_dependency_conflict.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/assess_has_dependency_conflict.R -\name{cohort_metric.cohort_metric_dependency_conflict} -\alias{cohort_metric.cohort_metric_dependency_conflict} +\name{metric_score.cohort_metric_dependency_conflict} +\alias{metric_score.cohort_metric_dependency_conflict} \title{Score a package for presence of dependency conflicts} \usage{ -cohort_metric.cohort_metric_dependency_conflict(x, ...) +\method{metric_score}{cohort_metric_dependency_conflict}(x, ...) } \value{ \code{1} if any dependencies are missing or conflicting, otherwise \code{0} diff --git a/man/metric_score.cohort_metric_reverse_dependencies.Rd b/man/metric_score.cohort_metric_reverse_dependencies.Rd new file mode 100644 index 00000000..3a4ff24f --- /dev/null +++ b/man/metric_score.cohort_metric_reverse_dependencies.Rd @@ -0,0 +1,11 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/assess_reverse_dependencies.R +\name{metric_score.cohort_metric_reverse_dependencies} +\alias{metric_score.cohort_metric_reverse_dependencies} +\title{Metric for the assessment of reverse dependencies of a cohort.} +\usage{ +\method{metric_score}{cohort_metric_reverse_dependencies}(x, ...) +} +\description{ +Metric for the assessment of reverse dependencies of a cohort. +} diff --git a/man/pkg_assess.Rd b/man/pkg_assess.Rd index ff53fb5f..b85716f4 100644 --- a/man/pkg_assess.Rd +++ b/man/pkg_assess.Rd @@ -51,7 +51,7 @@ assessment applied. \item{\code{\link{assess_has_website}}}{a vector of associated website urls} \item{\code{\link{assess_news_current}}}{NEWS file contains entry for current version number} \item{\code{\link{assess_export_help}}}{exported objects have documentation} -\item{\code{\link{assess_reverse_dependencies}}}{List of reverse dependencies a package has} +\item{\code{\link{assess_reverse_dependencies}}}{Table of reverse dependencies for each package.} \item{\code{\link{assess_has_bug_reports_url}}}{presence of a bug reports url in repository} \item{\code{\link{assess_has_source_control}}}{a vector of associated source control urls} \item{\code{\link{assess_dependencies}}}{Package dependency conflicts} From 7ca681532af0630594f1e856c1b34e6ec22fe5e6 Mon Sep 17 00:00:00 2001 From: Eric Milliman Date: Tue, 12 Apr 2022 16:11:24 -0400 Subject: [PATCH 26/50] cohort_score function, akin to pkg_score --- R/cohort_score.R | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 R/cohort_score.R diff --git a/R/cohort_score.R b/R/cohort_score.R new file mode 100644 index 00000000..68857ace --- /dev/null +++ b/R/cohort_score.R @@ -0,0 +1,21 @@ +#' Score a cohort assessment, collapsing results into a single numeric +#' cohort_score() calculates the risk involved with using a cohort of packages. Risk ranges +#' from 0 (low-risk) to 1 (high-risk). +#' +#' @export +cohort_score <- function(x, ..., error_handler = score_error_default) { + UseMethod("cohort_score") +} + +#' @export +cohort_score.list_of_cohort_metric <- function(x, ..., + error_handler = score_error_default) { + + lapply(x, function(xi) { + s <- metric_score(xi, error_handler = error_handler) + metric_score_s3_fun <- firstS3method("metric_score", class(xi)) + attr(s, "label") <- attr(metric_score_s3_fun, "label") + class(s) <- c("cohort_score", class(s)) + s + }) +} From 9fb36c769eb93b739b22e10befbc53cd14e1daa3 Mon Sep 17 00:00:00 2001 From: Eric Milliman Date: Tue, 12 Apr 2022 16:28:29 -0400 Subject: [PATCH 27/50] fixed some copy pasta errors --- R/assess_reverse_dependencies.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/R/assess_reverse_dependencies.R b/R/assess_reverse_dependencies.R index 5a12c2f1..c33b2edf 100644 --- a/R/assess_reverse_dependencies.R +++ b/R/assess_reverse_dependencies.R @@ -73,9 +73,9 @@ attributes(metric_score.pkg_metric_reverse_dependencies)$label <- #' #' @importFrom igraph fit_power_law #' @export -cohort_metric.cohort_metric_reverse_dependencies <- function(x, ...){ - igraph::fit_power_law(tapply(cohort_rev_deps$revdep,cohort_rev_deps$pkg, length))$KS.p +metric_score.cohort_metric_reverse_dependencies <- function(x, ...){ + igraph::fit_power_law(tapply(x$revdep, x$pkg, length))$KS.p } -attributes(cohort_metric.cohort_metric_reverse_dependencies)$label <- +attributes(metric_score.cohort_metric_reverse_dependencies)$label <- "p-value of power law distribution fit" From 9760f62dd588e9c01e6d81ae4a8a77371f3c80da Mon Sep 17 00:00:00 2001 From: Eric Milliman Date: Tue, 12 Apr 2022 16:28:59 -0400 Subject: [PATCH 28/50] renamed cohort_metric to metric_score --- R/assess_has_dependency_conflict.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/assess_has_dependency_conflict.R b/R/assess_has_dependency_conflict.R index 11d1afdc..03710066 100644 --- a/R/assess_has_dependency_conflict.R +++ b/R/assess_has_dependency_conflict.R @@ -46,9 +46,9 @@ assess_has_dependency_conflict.cohort_ref <- function(x, ...){ #' @return \code{1} if any dependencies are missing or conflicting, otherwise \code{0} #' #' @export -cohort_metric.cohort_metric_dependency_conflict <- function(x, ...) { +metric_score.cohort_metric_dependency_conflict <- function(x, ...) { as.numeric(NROW(x) > 0) } -attributes(cohort_metric.cohort_metric_dependency_conflict)$label <- +attributes(metric_score.cohort_metric_dependency_conflict)$label <- "A binary indicator of whether the cohort has missing or conflicting dependencies." From f327189c9b9f858606760bda641d2f7c6af51b6d Mon Sep 17 00:00:00 2001 From: Eric Milliman Date: Tue, 12 Apr 2022 16:29:34 -0400 Subject: [PATCH 29/50] changed return object type --- R/assess_exported_namespace.R | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/R/assess_exported_namespace.R b/R/assess_exported_namespace.R index 4ffa6a6d..8aa5f375 100644 --- a/R/assess_exported_namespace.R +++ b/R/assess_exported_namespace.R @@ -40,7 +40,9 @@ assess_exported_namespace.pkg_source <- function(x, ...) { #' @export assess_exported_namespace.cohort_ref <- function(x, ...) { ns <- unlist(lapply(x$cohort, assess_exported_namespace)) - + return(cohort_metric_eval(class = "cohort_metric_exported_namespaces", + ns + )) } From 0656aa54c3efa1c0ccb570f338f9afc94eb8e79d Mon Sep 17 00:00:00 2001 From: Eric Milliman Date: Wed, 13 Apr 2022 10:35:57 -0400 Subject: [PATCH 30/50] added metric_score for cohort_ref assessment. fixed class typo in assessment return object --- R/assess_exported_namespace.R | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/R/assess_exported_namespace.R b/R/assess_exported_namespace.R index 8aa5f375..0127985d 100644 --- a/R/assess_exported_namespace.R +++ b/R/assess_exported_namespace.R @@ -40,7 +40,7 @@ assess_exported_namespace.pkg_source <- function(x, ...) { #' @export assess_exported_namespace.cohort_ref <- function(x, ...) { ns <- unlist(lapply(x$cohort, assess_exported_namespace)) - return(cohort_metric_eval(class = "cohort_metric_exported_namespaces", + return(cohort_metric_eval(class = "cohort_metric_exported_namespace", ns )) } @@ -70,3 +70,29 @@ metric_score.pkg_metric_exported_namespace <- function(x, ...) { attributes(metric_score.pkg_metric_exported_namespace)$label <- "The number of exported objects in a package" + + +#' Score a cohort for the number of exported objects +#' +#' Score a cohort for the number of exported objects it has; regularized +#' Convert the number of exported objects \code{length(x)} into a validation +#' score [0,1] \deqn{ 1 / (1 + exp(-0.5 * (sqrt(length(x)) + sqrt(5)))) } +#' +#' The scoring function is the classic logistic curve \deqn{ +#' 1 / (1 + exp(-k(x-x[0])) } with a square root scale for the number of exported objects +#' \eqn{x = sqrt(length(x))}, sigmoid midpoint is 25 exported objects, ie. \eqn{x[0] = +#' sqrt(5)}, and logistic growth rate of \eqn{k = 0.25}. +#' +#' \deqn{ 1 / (1 + exp(-0.25 * sqrt(length(x))-sqrt(25))) } +#' +#' @eval roxygen_score_family("exported_namespace") +#' @return numeric value between \code{0} (high number of exported objects) and +#' \code{1} (low number of exported objects) +#' +#' @export +metric_score.cohort_metric_exported_namespace <- function(x, ...) { + 1 - 1 / (1 + exp(-0.25 * (sqrt(length(x)) - sqrt(25)))) +} + +attributes(metric_score.cohort_metric_exported_namespace)$label <- + "The number of exported objects in a cohort" From aa13d58fa1be9b0d6d9de41904fdf85c095d4ab2 Mon Sep 17 00:00:00 2001 From: Eric Milliman Date: Wed, 13 Apr 2022 10:36:13 -0400 Subject: [PATCH 31/50] fixed attribute typos --- R/assess_has_dependency_conflict.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/assess_has_dependency_conflict.R b/R/assess_has_dependency_conflict.R index 03710066..b7d9b916 100644 --- a/R/assess_has_dependency_conflict.R +++ b/R/assess_has_dependency_conflict.R @@ -5,8 +5,8 @@ assess_has_dependency_conflict <- function(x, ...){ UseMethod("assess_has_dependency_conflict") } -attributes(assess_dependencies)$column_name <- "dependency_conflict" -attributes(assess_dependencies)$label <- "Package dependency conflicts" +attributes(assess_has_dependency_conflict)$column_name <- "dependency_conflict" +attributes(assess_has_dependency_conflict)$label <- "Cohort dependency conflicts" #' @export assess_has_dependency_conflict.cohort_ref <- function(x, ...){ From 8b4c500ed122cc583334ceaaee014313087bf506 Mon Sep 17 00:00:00 2001 From: Eric Milliman Date: Wed, 13 Apr 2022 10:36:28 -0400 Subject: [PATCH 32/50] added summarized cohort score --- R/cohort_score.R | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/R/cohort_score.R b/R/cohort_score.R index 68857ace..be89e533 100644 --- a/R/cohort_score.R +++ b/R/cohort_score.R @@ -11,11 +11,13 @@ cohort_score <- function(x, ..., error_handler = score_error_default) { cohort_score.list_of_cohort_metric <- function(x, ..., error_handler = score_error_default) { - lapply(x, function(xi) { + metrics <- lapply(x, function(xi) { s <- metric_score(xi, error_handler = error_handler) metric_score_s3_fun <- firstS3method("metric_score", class(xi)) attr(s, "label") <- attr(metric_score_s3_fun, "label") class(s) <- c("cohort_score", class(s)) s }) + metrics[["cohort_score"]] <- summarize_scores(metrics, ...) + return(metrics) } From 460feca220785a771fb0b4095e7326870a0015b2 Mon Sep 17 00:00:00 2001 From: Eric Milliman Date: Fri, 15 Apr 2022 13:03:26 -0400 Subject: [PATCH 33/50] namespace and description updates --- DESCRIPTION | 4 +++- NAMESPACE | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 071edfa0..0bb209c7 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -35,7 +35,9 @@ Imports: pillar, tibble, pkgload, - devtools + devtools, + igraph, + dplyr Suggests: knitr, rmarkdown, diff --git a/NAMESPACE b/NAMESPACE index 32b5a5c8..e41e4d07 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -55,6 +55,7 @@ S3method(format,pkg_metric_error) S3method(format,pkg_missing) S3method(format,pkg_ref) S3method(metric_score,cohort_metric_dependency_conflict) +S3method(metric_score,cohort_metric_exported_namespace) S3method(metric_score,cohort_metric_reverse_dependencies) S3method(metric_score,default) S3method(metric_score,pkg_metric_covr_coverage) From 87d14b376b067410a371a28d183b42792037674a Mon Sep 17 00:00:00 2001 From: Eric Milliman Date: Fri, 15 Apr 2022 13:04:50 -0400 Subject: [PATCH 34/50] removed unnessary assessment checks due to rework of where dependecy info is cached. --- R/assess_dependencies.R | 8 -------- 1 file changed, 8 deletions(-) diff --git a/R/assess_dependencies.R b/R/assess_dependencies.R index 9e1f25e9..0b073490 100644 --- a/R/assess_dependencies.R +++ b/R/assess_dependencies.R @@ -39,26 +39,18 @@ assess_dependencies.pkg_install <- function(x, ...){ #' @export assess_dependencies.pkg_cran_remote <- function(x, ...){ - if(is.na(x$dependencies)){ - as_pkg_metric_error(error = 'Could not determine which CRAN mirror you are using.') - } else{ pkg_metric_eval(class = "pkg_metric_dependencies", { NROW(x$dependencies) }) - } } #' @importFrom BiocManager repositories #' @export assess_dependencies.pkg_bioc_remote <- function(x, ...){ - if(is.na(x$dependencies)){ - as_pkg_metric_error(error = 'Could not determine which BioC mirror you are using.') - } else{ pkg_metric_eval(class = "pkg_metric_dependencies", { NROW(x$dependencies) }) } -} #' Score a package for dependencies #' From 1291b2175769573658ff092da557f6e065cf2070 Mon Sep 17 00:00:00 2001 From: Eric Milliman Date: Fri, 15 Apr 2022 13:08:14 -0400 Subject: [PATCH 35/50] tried to added an assessment for a pkg_ref to satisfy metric_label unit test --- R/assess_has_dependency_conflict.R | 11 +++++++++-- R/metric_score.R | 15 ++++++++------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/R/assess_has_dependency_conflict.R b/R/assess_has_dependency_conflict.R index b7d9b916..4b72fdfd 100644 --- a/R/assess_has_dependency_conflict.R +++ b/R/assess_has_dependency_conflict.R @@ -8,6 +8,14 @@ assess_has_dependency_conflict <- function(x, ...){ attributes(assess_has_dependency_conflict)$column_name <- "dependency_conflict" attributes(assess_has_dependency_conflict)$label <- "Cohort dependency conflicts" +assess_has_dependency_conflict.pkg_ref <- function(x, ...){ + as_pkg_metric_na( + pkg_metric(class = "pkg_metric_dependency_conflict"), + message = "Dependency conflicts not relevant for an individual package.") +} +attributes(assess_has_dependency_conflict)$column_name <- "dependency_conflict" +attributes(assess_has_dependency_conflict)$label <- "Cohort dependency conflicts" + #' @export assess_has_dependency_conflict.cohort_ref <- function(x, ...){ dep <- lapply(x$cohort, "[[", "dependencies") @@ -50,5 +58,4 @@ metric_score.cohort_metric_dependency_conflict <- function(x, ...) { as.numeric(NROW(x) > 0) } -attributes(metric_score.cohort_metric_dependency_conflict)$label <- - "A binary indicator of whether the cohort has missing or conflicting dependencies." +attributes(metric_score.cohort_metric_dependency_conflict)$label <- "Binary indicator of the presence of a dependency conflict" diff --git a/R/metric_score.R b/R/metric_score.R index a5e92523..0777ee45 100644 --- a/R/metric_score.R +++ b/R/metric_score.R @@ -15,13 +15,12 @@ metric_score <- function(x, ...) { } - #' @export metric_score.default <- function(x, ...) { - if (!inherits(x, "pkg_metric")) { + if (!inherits(x, "pkg_metric") | !inherits(x, "cohort_metric")) { warning(sprintf(paste0( "Don't know how to score object of class %s. score is only intended ", - "to be used with objects inheriting class 'pkg_metric', ", + "to be used with objects inheriting class 'pkg_metric' or 'cohort_metric', ", "returning default score of 0."), paste0('"', class(x), '"', collapse = ", "))) } else { @@ -34,7 +33,6 @@ metric_score.default <- function(x, ...) { 0L } - metric_score_condition <- function(x, ...) { UseMethod("metric_score_condition") } @@ -46,15 +44,18 @@ metric_score_condition.pkg_metric_error <- function(x, ..., metric_score_condition.pkg_metric_na <- function(x, ...) { - structure(NA_real_, class = c("pkg_score_na", "numeric")) + structure(NA_real_, class = c("pkg_score_na", "numeric"), + label="No scoring method for metric" ) } metric_score_condition.pkg_metric_error <- function(x, ...) { - structure(NA_real_, class = c("pkg_score_error", "numeric")) + structure(NA_real_, class = c("pkg_score_error", "numeric"), + label="There was an error scoring this assessment" ) } metric_score_condition.pkg_metric_todo <- function(x, ...) { - structure(NA_real_, class = c("pkg_score_todo", "numeric")) + structure(NA_real_, class = c("pkg_score_todo", "numeric"), + label="A scoring method for this assessment will be implemented in the future" ) } From b212f4a3848975892e039647a263f28e90cac723 Mon Sep 17 00:00:00 2001 From: Eric Milliman Date: Fri, 15 Apr 2022 13:08:40 -0400 Subject: [PATCH 36/50] fixed test now that table of dependencies is cached instead of computed at assessment. --- tests/testthat/test_assess_dependencies.R | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/testthat/test_assess_dependencies.R b/tests/testthat/test_assess_dependencies.R index a375086d..92fdc337 100644 --- a/tests/testthat/test_assess_dependencies.R +++ b/tests/testthat/test_assess_dependencies.R @@ -4,7 +4,6 @@ test_that("assess_dependencies returns the correct number of dependencies", { c("pkg_metric_dependencies", "pkg_metric", "data.frame")) expect_equal( - nrow(assess_source_good$dependencies), - 0) + assess_source_good$dependencies, 1, ignore_attr=TRUE) }) From c4aa559aba7c2495699a1d24406b4f74b7e4ceae Mon Sep 17 00:00:00 2001 From: Eric Milliman Date: Fri, 15 Apr 2022 13:10:02 -0400 Subject: [PATCH 37/50] documentation updated --- R/pkg_metric.R | 1 - ..._score.cohort_metric_exported_namespace.Rd | 34 +++++++++++++++++++ man/pkg_assess.Rd | 4 +-- 3 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 man/metric_score.cohort_metric_exported_namespace.Rd diff --git a/R/pkg_metric.R b/R/pkg_metric.R index 81ed4598..01f7b5b2 100644 --- a/R/pkg_metric.R +++ b/R/pkg_metric.R @@ -14,7 +14,6 @@ pkg_metric <- function(x = NA, ..., class = c()) { } - #' Convert an object to a \code{pkg_metric} #' #' @inheritParams pkg_metric diff --git a/man/metric_score.cohort_metric_exported_namespace.Rd b/man/metric_score.cohort_metric_exported_namespace.Rd new file mode 100644 index 00000000..6bc10c1c --- /dev/null +++ b/man/metric_score.cohort_metric_exported_namespace.Rd @@ -0,0 +1,34 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/assess_exported_namespace.R +\name{metric_score.cohort_metric_exported_namespace} +\alias{metric_score.cohort_metric_exported_namespace} +\title{Score a cohort for the number of exported objects} +\usage{ +\method{metric_score}{cohort_metric_exported_namespace}(x, ...) +} +\arguments{ +\item{x}{a \code{pkg_metric_exported_namespace} packge metric object} + +\item{...}{additional arguments unused} +} +\value{ +numeric value between \code{0} (high number of exported objects) and + \code{1} (low number of exported objects) +} +\description{ +Score a cohort for the number of exported objects it has; regularized +Convert the number of exported objects \code{length(x)} into a validation +score [0,1] \deqn{ 1 / (1 + exp(-0.5 * (sqrt(length(x)) + sqrt(5)))) } +} +\details{ +The scoring function is the classic logistic curve \deqn{ +1 / (1 + exp(-k(x-x[0])) } with a square root scale for the number of exported objects +\eqn{x = sqrt(length(x))}, sigmoid midpoint is 25 exported objects, ie. \eqn{x[0] = +sqrt(5)}, and logistic growth rate of \eqn{k = 0.25}. + +\deqn{ 1 / (1 + exp(-0.25 * sqrt(length(x))-sqrt(25))) } +} +\examples{ +\dontrun{metric_score(assess_exported_namespace(pkg_ref("riskmetric"))) +} +} diff --git a/man/pkg_assess.Rd b/man/pkg_assess.Rd index b85716f4..dd37a50c 100644 --- a/man/pkg_assess.Rd +++ b/man/pkg_assess.Rd @@ -46,7 +46,7 @@ assessment applied. \item{\code{\link{assess_last_30_bugs_status}}}{vector indicating whether BugReports status is closed} \item{\code{\link{assess_license}}}{software is released with an acceptable license} \item{\code{\link{assess_downloads_1yr}}}{number of downloads in the past year} -\item{\code{\link{assess_has_dependency_conflict}}}{assess_has_dependency_conflict} +\item{\code{\link{assess_has_dependency_conflict}}}{Cohort dependency conflicts} \item{\code{\link{assess_exported_namespace}}}{Objects exported by package} \item{\code{\link{assess_has_website}}}{a vector of associated website urls} \item{\code{\link{assess_news_current}}}{NEWS file contains entry for current version number} @@ -54,7 +54,7 @@ assessment applied. \item{\code{\link{assess_reverse_dependencies}}}{Table of reverse dependencies for each package.} \item{\code{\link{assess_has_bug_reports_url}}}{presence of a bug reports url in repository} \item{\code{\link{assess_has_source_control}}}{a vector of associated source control urls} -\item{\code{\link{assess_dependencies}}}{Package dependency conflicts} +\item{\code{\link{assess_dependencies}}}{Package dependency footprint} \item{\code{\link{assess_has_vignettes}}}{number of discovered vignettes files} \item{\code{\link{assess_has_maintainer}}}{a vector of associated maintainers} \item{\code{\link{assess_r_cmd_check}}}{Package check results} From ab9fc812dd3cadf360e1fa6f67e42b73f5c2259c Mon Sep 17 00:00:00 2001 From: Eric Milliman Date: Fri, 15 Apr 2022 13:50:17 -0400 Subject: [PATCH 38/50] added a conditional. If no S3 methods exist for the classess provided, get the default method. --- R/utils.R | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/R/utils.R b/R/utils.R index 919c728f..3393edf4 100644 --- a/R/utils.R +++ b/R/utils.R @@ -80,8 +80,13 @@ firstS3method <- function(f, classes, envir = parent.frame()) { envir = envir, optional = TRUE) - # [1][[1]] hacky way of getting first elem while coercing empty list to NULL - Filter(Negate(is.null), s3methods)[1][[1]] + # [1][[1]] hacky way of getting first element while coercing empty list to NULL + mthd <- Filter(Negate(is.null), s3methods)[1][[1]] + if(is.null(mthd)){ + return(utils::getS3method(f=f, class = "default", envir = envir)) + } else{ + return(mthd) + } } From 12dfe71bc85043990529b52b8722b0ce88c80245 Mon Sep 17 00:00:00 2001 From: Eric Milliman Date: Fri, 15 Apr 2022 14:10:21 -0400 Subject: [PATCH 39/50] added labels to all metric_score_* functions. this is to help ensure unit tests pass --- R/metric_score.R | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/R/metric_score.R b/R/metric_score.R index a5e92523..82329f4b 100644 --- a/R/metric_score.R +++ b/R/metric_score.R @@ -33,6 +33,7 @@ metric_score.default <- function(x, ...) { 0L } +attributes(metric_score.default)$label <- "No method available to score assessment, or an error occured" metric_score_condition <- function(x, ...) { @@ -43,11 +44,13 @@ metric_score_condition.pkg_metric_error <- function(x, ..., error_handler = score_error_default) { error_handler(x, ...) } - +attributes(metric_score_condition.pkg_metric_error)$label <- "No method available to score assessment, an error occured" metric_score_condition.pkg_metric_na <- function(x, ...) { structure(NA_real_, class = c("pkg_score_na", "numeric")) } +attributes(metric_score_condition.pkg_metric_na)$label <- "No method available to score an assessment that returns NA" + metric_score_condition.pkg_metric_error <- function(x, ...) { structure(NA_real_, class = c("pkg_score_error", "numeric")) @@ -56,7 +59,7 @@ metric_score_condition.pkg_metric_error <- function(x, ...) { metric_score_condition.pkg_metric_todo <- function(x, ...) { structure(NA_real_, class = c("pkg_score_todo", "numeric")) } - +attributes(metric_score_condition.pkg_metric_todo)$label <- "No scoring method available because the assessment has yet to be implemented." #' Default score error handling, emitting a warning and returning 0 From c63452f8e8c6591e5a14122898bf8c2ef3462625 Mon Sep 17 00:00:00 2001 From: Eric Milliman Date: Fri, 15 Apr 2022 15:16:27 -0400 Subject: [PATCH 40/50] moved dplyr to imports...for now. ulitmately want to remove it as a dependency --- DESCRIPTION | 1 - 1 file changed, 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 0bb209c7..aa2d17b8 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -43,7 +43,6 @@ Suggests: rmarkdown, withr, magrittr, - dplyr, testthat, webmockr, jsonlite From 08df7d37cd1f8fb01081cb69b4a5946be6ce1609 Mon Sep 17 00:00:00 2001 From: Eric Milliman Date: Fri, 15 Apr 2022 15:17:38 -0400 Subject: [PATCH 41/50] fix argument consistentcy with print generic --- R/cohort_ref_class.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/cohort_ref_class.R b/R/cohort_ref_class.R index 65b881e6..6b9c6a40 100644 --- a/R/cohort_ref_class.R +++ b/R/cohort_ref_class.R @@ -70,7 +70,7 @@ as_tibble.cohort_ref <- function(x, ...) { #' @importFrom tibble tibble #' @method print cohort_ref #' @export -print.cohort_ref <- function(x){ +print.cohort_ref <- function(x, ...){ list(as_tibble(x$cohort), as_tibble(x$library)) } From 1bfadd0d2ec78a1039ab8d734a8331709c19d47f Mon Sep 17 00:00:00 2001 From: Eric Milliman Date: Fri, 15 Apr 2022 15:27:53 -0400 Subject: [PATCH 42/50] removed duplicate functions definitions --- R/assess_dependencies.R | 39 --------------------------------------- 1 file changed, 39 deletions(-) diff --git a/R/assess_dependencies.R b/R/assess_dependencies.R index 0b073490..acd4321d 100644 --- a/R/assess_dependencies.R +++ b/R/assess_dependencies.R @@ -127,42 +127,3 @@ remove_base_packages <- function(df){ deps <- df[!grepl("^R\\s\\(.+\\)", df$package) | df$package %in% base_rec_pkgs, ] ##Remove "R" dependencies as well as base and recomended return(deps) } - -#Helper functions to get extract dependencies - -#' Gets available packages from necessary repository and filters for -#' package of interest -#' -#' @param name package name -#' @param repo package repository (e.g. CRAN or Bioconductor) -#' -#' @return Returns a data frame with two columns 1) Package names, 2) type of dependency (LinkingTo, Imports, Depends) -#' -get_package_dependencies <- function(name, repo){ - ap <- available.packages(repo = repo) - deps <- ap[rownames(ap)==name, c("LinkingTo","Imports","Depends")] - deps <- deps[!is.na(deps)] - deps <- lapply(strsplit(deps, ","), trimws) - deps <- data.frame(package=unlist(deps), - type=rep(names(deps), sapply(deps, length)), - stringsAsFactors = FALSE, - row.names = NULL) - return(deps) -} - -#' Parse DCF of description file -#' -#' @param path pkg_ref path -#' -parse_dcf_dependencies <- function(path){ - dcf <- read.dcf(file.path(path, "DESCRIPTION"), all=TRUE) - dcf <- dcf[colnames(dcf) %in% c("LinkingTo","Imports", "Depends")] - dcf <- sapply(dcf, strsplit, strsplit, split=",") - dcf <- lapply(dcf, trimws) - deps <- data.frame(package=unlist(dcf), - type=rep(names(dcf), sapply(dcf, length)), - stringsAsFactors = FALSE, - row.names = NULL) - return(deps) -} - From 56f3031d9bc21fb16d92e051ec2f4386f377d6b6 Mon Sep 17 00:00:00 2001 From: Eric Milliman Date: Fri, 15 Apr 2022 15:32:04 -0400 Subject: [PATCH 43/50] added importFrom to assessment roxygen header --- R/assess_has_dependency_conflict.R | 2 ++ 1 file changed, 2 insertions(+) diff --git a/R/assess_has_dependency_conflict.R b/R/assess_has_dependency_conflict.R index 4b72fdfd..24b4359b 100644 --- a/R/assess_has_dependency_conflict.R +++ b/R/assess_has_dependency_conflict.R @@ -16,6 +16,8 @@ assess_has_dependency_conflict.pkg_ref <- function(x, ...){ attributes(assess_has_dependency_conflict)$column_name <- "dependency_conflict" attributes(assess_has_dependency_conflict)$label <- "Cohort dependency conflicts" +#' @importFrom stringr str_extract +#' @importFrom utils compareVersion #' @export assess_has_dependency_conflict.cohort_ref <- function(x, ...){ dep <- lapply(x$cohort, "[[", "dependencies") From df7d71aee864951c129f79e39678cfadfde75806 Mon Sep 17 00:00:00 2001 From: Eric Milliman Date: Fri, 15 Apr 2022 15:34:10 -0400 Subject: [PATCH 44/50] fixed function call from cohort_assessment to ass_cohort_assessment --- R/cohort_assess.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/cohort_assess.R b/R/cohort_assess.R index 28110250..04129fd9 100644 --- a/R/cohort_assess.R +++ b/R/cohort_assess.R @@ -21,7 +21,7 @@ #' @importFrom tibble as_tibble #' @importFrom vctrs new_list_of #' @export -cohort_assess <- function(x, assessments = cohort_assessments(), ..., +cohort_assess <- function(x, assessments = all_cohort_assessments(), ..., error_handler = assessment_error_empty) { UseMethod("cohort_assess") } From 5ed510e9b99e577aa88bfc0353323d74262f69a2 Mon Sep 17 00:00:00 2001 From: Eric Milliman Date: Fri, 15 Apr 2022 15:36:15 -0400 Subject: [PATCH 45/50] added import directive for installed.packages from utils --- R/cohort_ref_class.R | 1 + 1 file changed, 1 insertion(+) diff --git a/R/cohort_ref_class.R b/R/cohort_ref_class.R index 6b9c6a40..ceafafb9 100644 --- a/R/cohort_ref_class.R +++ b/R/cohort_ref_class.R @@ -5,6 +5,7 @@ #' #' @export #' @family cohort_ref +#' @importFrom utils installed.packages #' cohort_ref <- function(x, library = c("base", "recommended","installed"), lib.loc="", includeDependencies = TRUE, ...){ if (missing(x) & missing(library) & missing(lib.loc)) { From 5edc08e74b540e23917deb9c0e71f80caef2c850 Mon Sep 17 00:00:00 2001 From: Eric Milliman Date: Fri, 15 Apr 2022 15:50:50 -0400 Subject: [PATCH 46/50] documentation update --- NAMESPACE | 3 +++ man/cohort_assess.Rd | 2 +- man/get_package_dependencies.Rd | 7 ------- man/parse_dcf_dependencies.Rd | 4 ---- 4 files changed, 4 insertions(+), 12 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index e41e4d07..355ec5be 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -157,6 +157,7 @@ importFrom(pillar,new_pillar_shaft_simple) importFrom(pillar,pillar_shaft) importFrom(pillar,style_na) importFrom(pkgload,parse_ns_file) +importFrom(stringr,str_extract) importFrom(tibble,as_tibble) importFrom(tibble,tibble) importFrom(tools,Rd_db) @@ -169,8 +170,10 @@ importFrom(utils,.DollarNames) importFrom(utils,.S3methods) importFrom(utils,available.packages) importFrom(utils,capture.output) +importFrom(utils,compareVersion) importFrom(utils,getS3method) importFrom(utils,head) +importFrom(utils,installed.packages) importFrom(utils,packageDescription) importFrom(utils,packageName) importFrom(utils,packageVersion) diff --git a/man/cohort_assess.Rd b/man/cohort_assess.Rd index 54878365..56a7eefa 100644 --- a/man/cohort_assess.Rd +++ b/man/cohort_assess.Rd @@ -6,7 +6,7 @@ \usage{ cohort_assess( x, - assessments = cohort_assessments(), + assessments = all_cohort_assessments(), ..., error_handler = assessment_error_empty ) diff --git a/man/get_package_dependencies.Rd b/man/get_package_dependencies.Rd index 3a5fed3a..b2d151ef 100644 --- a/man/get_package_dependencies.Rd +++ b/man/get_package_dependencies.Rd @@ -5,8 +5,6 @@ \title{Gets available packages from necessary repository and filters for package of interest} \usage{ -get_package_dependencies(name, repo) - get_package_dependencies(name, repo) } \arguments{ @@ -15,14 +13,9 @@ get_package_dependencies(name, repo) \item{repo}{package repository (e.g. CRAN or Bioconductor)} } \value{ -Returns a data frame with two columns 1) Package names, 2) type of dependency (LinkingTo, Imports, Depends) - Returns a data frame with two columns 1) Package names, 2) type of dependency (LinkingTo, Imports, Depends) } \description{ -Gets available packages from necessary repository and filters for -package of interest - Gets available packages from necessary repository and filters for package of interest } diff --git a/man/parse_dcf_dependencies.Rd b/man/parse_dcf_dependencies.Rd index bbbdc94e..3e1abe33 100644 --- a/man/parse_dcf_dependencies.Rd +++ b/man/parse_dcf_dependencies.Rd @@ -4,15 +4,11 @@ \alias{parse_dcf_dependencies} \title{Parse DCF of description file} \usage{ -parse_dcf_dependencies(path) - parse_dcf_dependencies(path) } \arguments{ \item{path}{pkg_ref path} } \description{ -Parse DCF of description file - Parse DCF of description file } From ee35d8097ceaa5defb2216dfe23e0a156c05c3bb Mon Sep 17 00:00:00 2001 From: Eric Milliman Date: Fri, 15 Apr 2022 15:51:31 -0400 Subject: [PATCH 47/50] added stringr to imports. will investigate possibilibity of removing stringr depenedency --- DESCRIPTION | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index aa2d17b8..03bfd0f2 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -37,7 +37,8 @@ Imports: pkgload, devtools, igraph, - dplyr + dplyr, + stringr Suggests: knitr, rmarkdown, From 36fe2ba8e797c3280ea9ddd8ad605e7689001962 Mon Sep 17 00:00:00 2001 From: Eric Milliman Date: Tue, 19 Apr 2022 14:11:25 -0400 Subject: [PATCH 48/50] documentation updates --- NAMESPACE | 2 +- R/assess_has_dependency_conflict.R | 4 ++++ R/assess_reverse_dependencies.R | 2 ++ R/cohort_ref_class.R | 6 ++++++ R/cohort_score.R | 4 ++++ R/pkg_ref_class.R | 3 +++ man/as_list_of_pkg_ref.Rd | 3 +++ man/assess_has_dependency_conflict.Rd | 5 +++++ man/cohort_ref.Rd | 11 +++++++++++ man/cohort_score.Rd | 7 +++++++ man/metric_score.cohort_metric_dependency_conflict.Rd | 5 +++++ ...metric_score.cohort_metric_reverse_dependencies.Rd | 5 +++++ man/new_list_of_pkg_ref.Rd | 3 +++ 13 files changed, 59 insertions(+), 1 deletion(-) diff --git a/NAMESPACE b/NAMESPACE index 355ec5be..8f135e95 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -32,6 +32,7 @@ S3method(assess_exported_namespace,cohort_ref) S3method(assess_exported_namespace,default) S3method(assess_exported_namespace,pkg_install) S3method(assess_exported_namespace,pkg_source) +S3method(assess_has_bug_reports_url,pkg_ref) S3method(assess_has_dependency_conflict,cohort_ref) S3method(assess_has_news,pkg_ref) S3method(assess_has_vignettes,pkg_ref) @@ -106,7 +107,6 @@ export(assess_downloads_1yr) export(assess_export_help) export(assess_exported_namespace) export(assess_has_bug_reports_url) -export(assess_has_bug_reports_url.pkg_ref) export(assess_has_dependency_conflict) export(assess_has_maintainer) export(assess_has_news) diff --git a/R/assess_has_dependency_conflict.R b/R/assess_has_dependency_conflict.R index 24b4359b..adb4ce06 100644 --- a/R/assess_has_dependency_conflict.R +++ b/R/assess_has_dependency_conflict.R @@ -1,5 +1,7 @@ #' Assess a cohort for the presence of dependency conflicts #' +#' @param x cohort_ref +#' @param ... currently ignored #' @export #' assess_has_dependency_conflict <- function(x, ...){ @@ -53,6 +55,8 @@ assess_has_dependency_conflict.cohort_ref <- function(x, ...){ #' Score a package for presence of dependency conflicts #' +#' @param x cohort assessment +#' @param ... named list of arguments to adjust metric scoring. currently ignored. #' @return \code{1} if any dependencies are missing or conflicting, otherwise \code{0} #' #' @export diff --git a/R/assess_reverse_dependencies.R b/R/assess_reverse_dependencies.R index c33b2edf..dc7cd27e 100644 --- a/R/assess_reverse_dependencies.R +++ b/R/assess_reverse_dependencies.R @@ -71,6 +71,8 @@ attributes(metric_score.pkg_metric_reverse_dependencies)$label <- #' Metric for the assessment of reverse dependencies of a cohort. #' +#' @param x cohort assessment +#' @param ... named list of arguments that are currently ignored #' @importFrom igraph fit_power_law #' @export metric_score.cohort_metric_reverse_dependencies <- function(x, ...){ diff --git a/R/cohort_ref_class.R b/R/cohort_ref_class.R index ceafafb9..34c17895 100644 --- a/R/cohort_ref_class.R +++ b/R/cohort_ref_class.R @@ -3,6 +3,12 @@ #' This is a class to hold a list of pkg_refs along with extra #' information about the environment the packages are to be used/installed in. #' +#' @param x either a list of `pkg_ref`s or a `list_of_pkg_ref` +#' @param library one of "base", "recommended" or "installed" to use as an environment for testing cohorts +#' @param includeDependencies logical. whether or not to added add all pkg dependencies when creating a cohort [default: TRUE] +#' @param lib.loc path to R library +#' @param ... named vector or list of paramters to be included in cohort ref creation +#' #' @export #' @family cohort_ref #' @importFrom utils installed.packages diff --git a/R/cohort_score.R b/R/cohort_score.R index be89e533..5937845f 100644 --- a/R/cohort_score.R +++ b/R/cohort_score.R @@ -2,6 +2,10 @@ #' cohort_score() calculates the risk involved with using a cohort of packages. Risk ranges #' from 0 (low-risk) to 1 (high-risk). #' +#' @param x cohort assessment +#' @param ... named list of arguments to be used when scoring a cohort +#' @param error_handler error handling function +#' #' @export cohort_score <- function(x, ..., error_handler = score_error_default) { UseMethod("cohort_score") diff --git a/R/pkg_ref_class.R b/R/pkg_ref_class.R index c318d1db..421db1aa 100644 --- a/R/pkg_ref_class.R +++ b/R/pkg_ref_class.R @@ -377,6 +377,8 @@ verify_pkg_source <- function(x, source, repos) { #' Coerce a list or pkg_ref to a list_list_of_pkg_ref #' +#' @param x list of pkg_refs to be coerced to a `list_of_pkg_ref` +#' #' @importFrom vctrs new_list_of #' @export as_list_of_pkg_ref <- function(x){ @@ -385,6 +387,7 @@ as_list_of_pkg_ref <- function(x){ #' Create a list_list_of_pkg_ref from list of pkg_refs #' +#' @param x list of pkg_refs #' @importFrom vctrs new_list_of #' @export new_list_of_pkg_ref <- function(x){ diff --git a/man/as_list_of_pkg_ref.Rd b/man/as_list_of_pkg_ref.Rd index c82a823b..81d07e6c 100644 --- a/man/as_list_of_pkg_ref.Rd +++ b/man/as_list_of_pkg_ref.Rd @@ -6,6 +6,9 @@ \usage{ as_list_of_pkg_ref(x) } +\arguments{ +\item{x}{list of pkg_refs to be coerced to a `list_of_pkg_ref`} +} \description{ Coerce a list or pkg_ref to a list_list_of_pkg_ref } diff --git a/man/assess_has_dependency_conflict.Rd b/man/assess_has_dependency_conflict.Rd index 98b9927b..5ea05158 100644 --- a/man/assess_has_dependency_conflict.Rd +++ b/man/assess_has_dependency_conflict.Rd @@ -6,6 +6,11 @@ \usage{ assess_has_dependency_conflict(x, ...) } +\arguments{ +\item{x}{cohort_ref} + +\item{...}{currently ignored} +} \description{ Assess a cohort for the presence of dependency conflicts } diff --git a/man/cohort_ref.Rd b/man/cohort_ref.Rd index 0df3ec38..76634444 100644 --- a/man/cohort_ref.Rd +++ b/man/cohort_ref.Rd @@ -12,6 +12,17 @@ cohort_ref( ... ) } +\arguments{ +\item{x}{either a list of `pkg_ref`s or a `list_of_pkg_ref`} + +\item{library}{one of "base", "recommended" or "installed" to use as an environment for testing cohorts} + +\item{lib.loc}{path to R library} + +\item{includeDependencies}{logical. whether or not to added add all pkg dependencies when creating a cohort [default: TRUE]} + +\item{...}{named vector or list of paramters to be included in cohort ref creation} +} \description{ This is a class to hold a list of pkg_refs along with extra information about the environment the packages are to be used/installed in. diff --git a/man/cohort_score.Rd b/man/cohort_score.Rd index ef169bc2..d8d55272 100644 --- a/man/cohort_score.Rd +++ b/man/cohort_score.Rd @@ -8,6 +8,13 @@ from 0 (low-risk) to 1 (high-risk).} \usage{ cohort_score(x, ..., error_handler = score_error_default) } +\arguments{ +\item{x}{cohort assessment} + +\item{...}{named list of arguments to be used when scoring a cohort} + +\item{error_handler}{error handling function} +} \description{ Score a cohort assessment, collapsing results into a single numeric cohort_score() calculates the risk involved with using a cohort of packages. Risk ranges diff --git a/man/metric_score.cohort_metric_dependency_conflict.Rd b/man/metric_score.cohort_metric_dependency_conflict.Rd index aad71bef..93c60329 100644 --- a/man/metric_score.cohort_metric_dependency_conflict.Rd +++ b/man/metric_score.cohort_metric_dependency_conflict.Rd @@ -6,6 +6,11 @@ \usage{ \method{metric_score}{cohort_metric_dependency_conflict}(x, ...) } +\arguments{ +\item{x}{cohort assessment} + +\item{...}{named list of arguments to adjust metric scoring. currently ignored.} +} \value{ \code{1} if any dependencies are missing or conflicting, otherwise \code{0} } diff --git a/man/metric_score.cohort_metric_reverse_dependencies.Rd b/man/metric_score.cohort_metric_reverse_dependencies.Rd index 3a4ff24f..3967c06a 100644 --- a/man/metric_score.cohort_metric_reverse_dependencies.Rd +++ b/man/metric_score.cohort_metric_reverse_dependencies.Rd @@ -6,6 +6,11 @@ \usage{ \method{metric_score}{cohort_metric_reverse_dependencies}(x, ...) } +\arguments{ +\item{x}{cohort assessment} + +\item{...}{named list of arguments that are currently ignored} +} \description{ Metric for the assessment of reverse dependencies of a cohort. } diff --git a/man/new_list_of_pkg_ref.Rd b/man/new_list_of_pkg_ref.Rd index 126450ae..7cf38fef 100644 --- a/man/new_list_of_pkg_ref.Rd +++ b/man/new_list_of_pkg_ref.Rd @@ -6,6 +6,9 @@ \usage{ new_list_of_pkg_ref(x) } +\arguments{ +\item{x}{list of pkg_refs} +} \description{ Create a list_list_of_pkg_ref from list of pkg_refs } From e40a7bfdd3863b1ec5fa9b7c5fdbe9666e01b30b Mon Sep 17 00:00:00 2001 From: Eric Milliman Date: Tue, 19 Apr 2022 14:12:03 -0400 Subject: [PATCH 49/50] made s3 dispatch consistent --- R/assess_has_bug_reports_url.R | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/R/assess_has_bug_reports_url.R b/R/assess_has_bug_reports_url.R index aa3e9ec8..27a61f0e 100644 --- a/R/assess_has_bug_reports_url.R +++ b/R/assess_has_bug_reports_url.R @@ -6,9 +6,7 @@ #' #' @export assess_has_bug_reports_url <- function(x, ...) { - pkg_metric_eval(class = "pkg_metric_has_bug_reports_url", { - as.character(x$bug_reports_url) - }) + UseMethod("assess_has_bug_reports_url") } # assign a friendly name for assess column @@ -20,7 +18,7 @@ attr(assess_has_bug_reports_url,"label") <- "presence of a bug reports url in re #' @export assess_has_bug_reports_url.pkg_ref <- function(x, ...) { pkg_metric(class = "pkg_metric_has_bug_reports_url", { - length(x$bug_reports_url) + as.character(x$bug_reports_url) }) } From b45ba6707dee2540c8049b0cdfede5e1d9977e89 Mon Sep 17 00:00:00 2001 From: Eric Milliman Date: Tue, 19 Apr 2022 14:12:19 -0400 Subject: [PATCH 50/50] updated test expectations --- tests/testthat/test_assess_dependencies.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test_assess_dependencies.R b/tests/testthat/test_assess_dependencies.R index 92fdc337..7b364ce1 100644 --- a/tests/testthat/test_assess_dependencies.R +++ b/tests/testthat/test_assess_dependencies.R @@ -4,6 +4,6 @@ test_that("assess_dependencies returns the correct number of dependencies", { c("pkg_metric_dependencies", "pkg_metric", "data.frame")) expect_equal( - assess_source_good$dependencies, 1, ignore_attr=TRUE) + assess_source_good$dependencies, 0, ignore_attr=TRUE) })