Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

added node coloring in DependencyReporter (fixes #238, #239) #243

Merged
merged 10 commits into from
Jul 21, 2020
Merged
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ importFrom(assertthat,is.readable)
importFrom(assertthat,is.string)
importFrom(assertthat,is.writeable)
importFrom(covr,package_coverage)
importFrom(data.table,":=")
importFrom(data.table,as.data.table)
importFrom(data.table,copy)
importFrom(data.table,data.table)
Expand Down
27 changes: 26 additions & 1 deletion R/DependencyReporter.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ NULL
#' @importFrom assertthat assert_that is.flag
#' @importFrom utils installed.packages
#' @importFrom tools package_dependencies
#' @importFrom data.table data.table rbindlist setkeyv
#' @importFrom data.table := data.table rbindlist setkeyv
#' @importFrom visNetwork visHierarchicalLayout
#' @export
DependencyReporter <- R6::R6Class(
Expand Down Expand Up @@ -221,6 +221,31 @@ DependencyReporter <- R6::R6Class(
}

, plot_network = function() {

# color base packages and the package in focus differently
gray <- "#dfdfdf"
orange <- "#FFBD33"
bright_green <- "#aafca8"

packageDT <- data.table::as.data.table(
installed.packages()
)
base_packages <- packageDT[!is.na(Priority) & Priority == "base"][, Package]

nodeDT <- self$nodes
nodeDT[, package_type := "regular_dependency"]
nodeDT[node %in% base_packages, package_type := "base_dependency"]
nodeDT[node == self$pkg_name, package_type := "report_package"]
private$update_nodes(nodeDT)
private$set_plot_node_color_scheme(
field = "package_type"
, palette = c(
"regular_dependency" = bright_green
, "report_package" = orange
, "base_dependency" = gray
)
)

g <- (
super$plot_network()
%>% visNetwork::visHierarchicalLayout(
Expand Down
6 changes: 6 additions & 0 deletions inst/package_report/package_dependency_reporter.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ output: html_document

This section analyzes the recursive package dependencies of **`r reporter$pkg_name`**.

In the plot below, you'll see the following colors:

- gray: **`r reporter$pkg_name`**
- orange: R packages available [in every R session by default](https://cran.r-project.org/doc/manuals/r-release/R-admin.html#Default-packages)
- green: third-party R packages

```{r echo = FALSE, error = TRUE}
reporter$calculate_default_measures()
```
Expand Down