diff --git a/NEWS.md b/NEWS.md index fd38151f0..7a8d3e7c3 100644 --- a/NEWS.md +++ b/NEWS.md @@ -8,6 +8,7 @@ * Fix typo in Privileges table (#719) * Fixed bug where HTML reports displayed a darker green in the cards' meters * Only run configuration checkers when configuring the database +* Added Package Dependencies to Reports (#721) # riskassessment 3.0.0 diff --git a/R/app_server.R b/R/app_server.R index 616e9091c..edb3240da 100644 --- a/R/app_server.R +++ b/R/app_server.R @@ -204,7 +204,7 @@ app_server <- function(input, output, session) { # Load server of the database view module. #parentSession <- .subset2(session, "parent") databaseViewServer("databaseView", user, uploaded_pkgs, - metric_weights = metric_weights, changes, parent = session) + metric_weights = metric_weights, dep_metrics, loaded2_db, changes, parent = session) # Gather maintenance metrics information. maint_metrics <- reactive({ @@ -223,6 +223,38 @@ app_server <- function(input, output, session) { get_comm_data(selected_pkg$name()) }) + loaded2_db <- eventReactive(selected_pkg$name(), { + req(selected_pkg$name()) + req(selected_pkg$name() != "-") + + dbSelect("SELECT name, version, score FROM package") + }) + + # Get Package Dependency metrics. + dep_metrics <- reactiveVal() + + pkgref <- eventReactive(selected_pkg$name(), { + req(selected_pkg$name()) + req(selected_pkg$name() != "-") + + get_assess_blob(selected_pkg$name()) + }) + + observeEvent(pkgref(), { + req(pkgref()) + tryCatch( + expr = { + dep_metrics(pkgref()$dependencies[[1]] %>% dplyr::as_tibble()) + }, + error = function(e) { + msg <- paste("Detailed dependency information is not available for package", selected_pkg$name()) + rlang::warn(msg) + rlang::warn(paste("info:", e)) + dep_metrics(dplyr::tibble(package = character(0), type = character(0), name = character(0))) + } + ) + }) + create_src_dir <- eventReactive(input$tabs, input$tabs == "Source Explorer") pkgdir <- reactiveVal() observe({ @@ -271,6 +303,13 @@ app_server <- function(input, output, session) { community_usage_metrics, user, credential_config) + + # Load server for the package dependencies tab. + dependencies_data <- packageDependenciesServer('packageDependencies', + selected_pkg, + loaded2_db, + user, + parent = session) # Load server of the report preview tab. reportPreviewServer(id = "reportPreview", @@ -282,17 +321,14 @@ app_server <- function(input, output, session) { cm_comments = community_data$comments, # se_comments = src_explorer_data$comments, # not an arg downloads_plot_data = community_data$downloads_plot_data, + dep_metrics = dep_metrics, + loaded2_db, user = user, credential_config, app_version = golem::get_golem_options('app_version'), metric_weights = metric_weights) - # Load server for the package dependencies tab. - dependencies_data <- packageDependenciesServer('packageDependencies', - selected_pkg, - user, - parent = session) - + output$auth_output <- renderPrint({ reactiveValuesToList(res_auth) }) diff --git a/R/mod_databaseView.R b/R/mod_databaseView.R index 05555476e..ca6d92b5b 100644 --- a/R/mod_databaseView.R +++ b/R/mod_databaseView.R @@ -98,6 +98,8 @@ databaseViewUI <- function(id) { #' @param user a user name #' @param uploaded_pkgs a vector of uploaded package names #' @param metric_weights a reactive data.frame holding metric weights +#' @param dep_metrics placeholder +#' @param loaded2_db placeholder #' @param changes a reactive value integer count #' @param parent the parent (calling module) session information #' @@ -112,7 +114,7 @@ databaseViewUI <- function(id) { #' @importFrom formattable formattable as.datatable formatter style csscolor #' icontext #' @keywords internal -databaseViewServer <- function(id, user, uploaded_pkgs, metric_weights, changes, parent) { +databaseViewServer <- function(id, user, uploaded_pkgs, metric_weights, dep_metrics, loaded2_db, changes, parent) { moduleServer(id, function(input, output, session) { ns = session$ns @@ -302,6 +304,7 @@ databaseViewServer <- function(id, user, uploaded_pkgs, metric_weights, changes, # return vector of elements to include in the report report_includes <- mod_downloadHandler_include_server("downloadHandler") - mod_downloadHandler_server("downloadHandler", pkgs, user, metric_weights) + mod_downloadHandler_server("downloadHandler", pkgs, user, metric_weights, dep_metrics, loaded2_db) + }) } diff --git a/R/mod_downloadHandler.R b/R/mod_downloadHandler.R index b460619f4..dc2694222 100644 --- a/R/mod_downloadHandler.R +++ b/R/mod_downloadHandler.R @@ -101,7 +101,7 @@ mod_downloadHandler_include_server <- function(id) { #' downloadHandler Server Functions #' #' @noRd -mod_downloadHandler_server <- function(id, pkgs, user, metric_weights){ +mod_downloadHandler_server <- function(id, pkgs, user, metric_weights, dep_metrics, loaded2_db){ moduleServer( id, function(input, output, session){ ns <- session$ns @@ -256,8 +256,20 @@ mod_downloadHandler_server <- function(id, pkgs, user, metric_weights){ comm_cards <- build_comm_cards(comm_data) downloads_plot <- build_comm_plotly(comm_data) metric_tbl <- dbSelect("select * from metric", db_name = golem::get_golem_options('assessment_db_name')) - - + dep_cards <- build_dep_cards(data = dep_metrics(), loaded = loaded2_db()$name, toggled = 0L) + + pkginfo <- dep_metrics() %>% + mutate(package = stringr::str_replace(package, "\n", " ")) %>% + mutate(name = stringr::str_extract(package, "^((([[A-z]]|[.][._[A-z]])[._[A-z0-9]]*)|[.])")) + + repo_pkgs <- as.data.frame(utils::available.packages()[,1:2]) + + dep_table <- purrr::map_df(pkginfo$name, ~get_versnScore(.x, loaded2_db(), repo_pkgs)) %>% + right_join(pkginfo, by = "name") %>% + select(package, type, version, score) %>% + arrange(package, type) %>% + distinct() + # Render the report, passing parameters to the rmd file. rmarkdown::render( input = Report, @@ -280,6 +292,8 @@ mod_downloadHandler_server <- function(id, pkgs, user, metric_weights){ com_metrics = comm_cards, com_metrics_raw = comm_data, downloads_plot_data = downloads_plot, + dep_cards = dep_cards, + dep_table = dep_table, metric_tbl = metric_tbl ) ) diff --git a/R/mod_packageDependencies.R b/R/mod_packageDependencies.R index 2d658178f..98dac496a 100644 --- a/R/mod_packageDependencies.R +++ b/R/mod_packageDependencies.R @@ -11,6 +11,7 @@ packageDependenciesUI <- function(id) { #' #' @param id a module id name #' @param selected_pkg placeholder +#' @param loaded2_db placeholder #' @param user placeholder #' @param parent the parent (calling module) session information #' @@ -27,14 +28,10 @@ packageDependenciesUI <- function(id) { #' #' @keywords internal #' -packageDependenciesServer <- function(id, selected_pkg, user, parent) { +packageDependenciesServer <- function(id, selected_pkg, loaded2_db, user, parent) { moduleServer(id, function(input, output, session) { ns <- session$ns - loaded2_db <- eventReactive(selected_pkg$name(), { - dbSelect("SELECT name, version, score FROM package") - }) - tabready <- reactiveVal(value = NULL) depends <- reactiveVal(value = NULL) suggests <- reactiveVal(value = NULL) diff --git a/R/mod_reportPreview.R b/R/mod_reportPreview.R index 26f01e7bc..78c391af3 100644 --- a/R/mod_reportPreview.R +++ b/R/mod_reportPreview.R @@ -20,6 +20,8 @@ reportPreviewUI <- function(id) { #' @param mm_comments placeholder #' @param cm_comments placeholder #' @param downloads_plot_data placeholder +#' @param dep_metrics placeholder +#' @param loaded2_db placeholder #' @param user placeholder #' @param app_version placeholder #' @param metric_weights placeholder @@ -35,10 +37,10 @@ reportPreviewUI <- function(id) { #' @importFrom shinyjs enable disable show hide disabled #' @keywords internal #' -reportPreviewServer <- function(id, selected_pkg, maint_metrics, com_metrics, +reportPreviewServer <- function(id, selected_pkg, maint_metrics, com_metrics, com_metrics_raw, mm_comments, cm_comments, #se_comments, - downloads_plot_data, user, credentials, app_version, - metric_weights) { + downloads_plot_data, dep_metrics, loaded2_db, user, credentials, + app_version, metric_weights) { if (missing(credentials)) credentials <- get_db_config("credentials") @@ -172,6 +174,33 @@ reportPreviewServer <- function(id, selected_pkg, maint_metrics, com_metrics, ) } else "", + if('Package Dependencies' %in% report_includes()) { + tagList( + br(), br(), + hr(), + fluidRow( + column(width = 12, + h5("Package Dependencies", + style = "text-align: center; padding-bottom: 50px;"), + metricGridUI(session$ns('dep_metricGrid')) + ) + ), + br(), br(), + fluidRow( + column(width = 8, + DT::renderDataTable({ + req(selected_pkg$name()) + + dep_table() + + }, options = list(dom = "t", searching = FALSE, pageLength = -1, lengthChange = FALSE, + info = FALSE, + columnDefs = list(list(className = 'dt-center', targets = 2)) + ) + ) + )) + ) + } else "", if(any(c('Source Explorer Comments') %in% report_includes())) { tagList( @@ -402,6 +431,28 @@ reportPreviewServer <- function(id, selected_pkg, maint_metrics, com_metrics, # Community usage metrics cards. metricGridServer("cm_metricGrid", metrics = com_metrics) + dep_cards <- eventReactive(dep_metrics(), { + req(dep_metrics()) + build_dep_cards(data = dep_metrics(), loaded = loaded2_db()$name, toggled = 0L) + }) + + # Package Dependencies metrics cards. + metricGridServer("dep_metricGrid", metrics = dep_cards) + + dep_table <- eventReactive(dep_metrics(), { + req(dep_metrics()) + pkginfo <- dep_metrics() %>% + mutate(package = stringr::str_replace(package, "\n", " ")) %>% + mutate(name = stringr::str_extract(package, "^((([[A-z]]|[.][._[A-z]])[._[A-z0-9]]*)|[.])")) + + repo_pkgs <- as.data.frame(utils::available.packages()[,1:2]) + purrr::map_df(pkginfo$name, ~get_versnScore(.x, loaded2_db(), repo_pkgs)) %>% + right_join(pkginfo, by = "name") %>% + select(package, type, version, score) %>% + arrange(package, type) %>% + distinct() + }) + output$communityMetrics_ui <- renderUI({ req(selected_pkg$name()) @@ -456,7 +507,7 @@ reportPreviewServer <- function(id, selected_pkg, maint_metrics, com_metrics, tagList( h5(code('{riskmetric}'), 'Assessment Date:'), selected_pkg$date_added(), - if('Risk Score' %in% report_includes()) tagList(h5('Risk Score:'), selected_pkg$score()) else "", + if('Risk Score' %in% report_includes()) tagList(hr(), br(), h5('Risk Score:'), selected_pkg$score()) else "", h5('Package Decision:'),ifelse(is.na(selected_pkg$decision()), 'Pending',selected_pkg$decision()) ) }) @@ -485,6 +536,6 @@ reportPreviewServer <- function(id, selected_pkg, maint_metrics, com_metrics, ) # Call download handler server - mod_downloadHandler_server("downloadHandler", selected_pkg$name, user, metric_weights) + mod_downloadHandler_server("downloadHandler", selected_pkg$name, user, metric_weights, dep_metrics, loaded2_db) }) } diff --git a/R/sysdata.rda b/R/sysdata.rda index 3cd5b4b0b..11002747f 100644 Binary files a/R/sysdata.rda and b/R/sysdata.rda differ diff --git a/data-raw/internal-data.R b/data-raw/internal-data.R index ab38bcf2a..86c1239d0 100644 --- a/data-raw/internal-data.R +++ b/data-raw/internal-data.R @@ -93,7 +93,7 @@ metric_lst <- c("1"='has_vignettes', "2"='has_news', "3"='news_current', "4"='ha rpt_choices <- c("Report Author", "Report Date", "Risk Score", "Overall Comment", "Package Summary", "Maintenance Metrics", "Maintenance Comments", "Community Usage Metrics", "Community Usage Comments", - "Source Explorer Comments", "Function Explorer Comments") + "Package Dependencies", "Source Explorer Comments", "Function Explorer Comments") usethis::use_data( # app_version, diff --git a/inst/report_downloads/header.docx b/inst/report_downloads/header.docx index 0b6cd4398..f1c6744a2 100644 Binary files a/inst/report_downloads/header.docx and b/inst/report_downloads/header.docx differ diff --git a/inst/report_downloads/header.tex b/inst/report_downloads/header.tex index 1e050a72f..09ffb6873 100644 --- a/inst/report_downloads/header.tex +++ b/inst/report_downloads/header.tex @@ -1,6 +1,8 @@ \usepackage{graphicx} \usepackage{fancyhdr} \usepackage{unicode-math} +\usepackage{booktabs} +\usepackage{tabularx} \fancypagestyle{plain}{\pagestyle{fancy}} \fancyhf{}% Clear header/footer \setlength{\headheight}{15pt} diff --git a/inst/report_downloads/reportDocx.Rmd b/inst/report_downloads/reportDocx.Rmd index 3e61a0f3d..ef9c2f530 100644 --- a/inst/report_downloads/reportDocx.Rmd +++ b/inst/report_downloads/reportDocx.Rmd @@ -27,6 +27,8 @@ params: com_metrics: NA com_metrics_raw: NA downloads_plot_data: NA + dep_cards: NA + dep_table: NA metric_tbl: NA --- @@ -40,6 +42,7 @@ params: ```{r setup, include=FALSE} library(knitr) +library(kableExtra) library(shiny) library(ggplot2) library(plotly) @@ -69,19 +72,19 @@ outputComments <- function(pkg_name, comments, none_txt = "No comments"){
```{r general_pkg_info} -h5('General Information') +h2('General Information') tagList( - strong('Package:'), br(), getElement(params$pkg, 'name'), br(), br(), - strong('Version:'), br(), getElement(params$pkg, 'version'), br(), br(), + strong('Package:'), getElement(params$pkg, 'name'), br(), br(), + strong('Version:'), getElement(params$pkg, 'version'), br(), br(), strong('Title:'), br(), getElement(params$pkg, 'title'), br(), br(), strong('Description:'), br(), getElement(params$pkg, 'description'), br(), br(), strong('Author:'), br(), getElement(params$pkg, 'author'), br(), br(), strong('Maintainer:'), br(), getElement(params$pkg, 'maintainer'), br(), br(), strong('License:'), br(), getElement(params$pkg, 'license'), br(), br(), - strong('Published:'), br(), getElement(params$pkg, 'published'), br(), br(), - strong(code('{riskmetric}'), 'Assessment Date:'), br(), getElement(params$pkg, 'date_added'), br(), br(), - if('Risk Score' %in% params$report_includes) tagList(strong('Risk Score:'), br(), getElement(params$pkg, 'score'), br(), br()) else "", - strong('Package Decision:'), br(), ifelse(is.na(params$pkg[['decision']]), 'Pending', params$pkg[['decision']]) + strong('Published:'), getElement(params$pkg, 'published'), br(), br(), + strong(code('{riskmetric}'), 'Assessment Date:'), getElement(params$pkg, 'date_added'), br(), + if('Risk Score' %in% params$report_includes) tagList(strong('Risk Score:'), getElement(params$pkg, 'score'), br(), br()) else "", br(), + strong('Package Decision:'), ifelse(is.na(params$pkg[['decision']]), 'Pending', params$pkg[['decision']]) ) ``` @@ -128,6 +131,8 @@ tagList(br(), h2('Maintenance Metrics')) if('Maintenance Metrics' %in% params$report_includes){ params$maint_metrics %>% dplyr::mutate( + score = na_if(score, "NA"), + score = na_if(score, "NULL"), `Metric Name` = title, `Metric Description` = desc, `Metric Value` = dplyr::case_when( @@ -143,11 +148,11 @@ if('Maintenance Metrics' %in% params$report_includes){ ) ) %>% dplyr::select(`Metric Name`, `Metric Description`, `Metric Value`, `Metric Score`) %>% - knitr::kable(format = 'pandoc') + kableExtra::kbl(format = 'pipe', booktabs = T) } ``` -`r if ('Maintenance Metrics' %in% params$report_includes) {"* Metrics whose score is NA will not impact the package {riskmetric} score"}` +`r if ('Maintenance Metrics' %in% params$report_includes) {"Metrics whose score is NA will not impact the package {riskmetric} score"}` ```{r maintenance_metrics_comments} if('Maintenance Comments' %in% params$report_includes){ @@ -179,6 +184,8 @@ if (!cm_ind) { if('Community Usage Metrics' %in% params$report_includes){ params$com_metrics %>% dplyr::mutate( + score = na_if(score, "NA"), + score = na_if(score, "NULL"), `Metric Name` = title, `Metric Description` = desc, `Metric Value` = ifelse(value %in% c("pkg_metric_error", "NA", NA), "Not found", value), @@ -190,12 +197,12 @@ if (!cm_ind) { ) ) %>% dplyr::select(`Metric Name`, `Metric Description`, `Metric Value`, `Metric Score`) %>% - knitr::kable(format = 'pandoc') + kableExtra::kbl(format = 'pipe', booktabs = T) } } ``` -`r if ('Community Usage Metrics' %in% params$report_includes) {"* Metrics whose score is NA will not impact the package {riskmetric} score"}` +`r if ('Community Usage Metrics' %in% params$report_includes) {"Metrics whose score is NA will not impact the package {riskmetric} score"}` ```{r community_metrics_plot_title, eval=cm_ind} if('Community Usage Metrics' %in% params$report_includes){ @@ -243,6 +250,52 @@ if('Community Usage Comments' %in% params$report_includes){ } ``` +```{r package_dependencies_header} + if('Package Dependencies' %in% params$report_includes) { + tagList(br(), h2("Package Dependencies"), br()) + } else "" +``` + +```{r package_dependencies_cards} + if('Package Dependencies' %in% params$report_includes) { + cards <- params$dep_cards %>% + dplyr::mutate( + score = na_if(score, "NA"), + score = na_if(score, "NULL"), + `Metric Name` = title, + `Metric Description` = desc, + `Metric Value` = ifelse(value %in% c("pkg_metric_error", "NA", NA), "Not found", value), + `Metric Score` = dplyr::case_when(toupper(score) %in% c("NA", "NULL") ~ "NA", + # flip the label display of the score to mimic the package score... + round(as.numeric(score), 2) == 0 ~ "1.0", + round(as.numeric(score), 2) == 1 ~ "0.0", + TRUE ~ as.character(round(1 - as.numeric(score), 2)) + ) + ) %>% + dplyr::select(`Metric Name`, `Metric Description`, `Metric Value`, `Metric Score`) %>% + dplyr::mutate(`Metric Description` = stringr::str_replace_all(`Metric Description`, 'by Type', '
by Type')) %>% + dplyr::mutate(`Metric Description` = stringr::str_replace_all(`Metric Description`, 'from Base', '
from Base')) %>% + dplyr::mutate(`Metric Value` = stringr::str_replace_all(`Metric Value`, '\n' ,'
')) + + kableExtra::kbl(cards, format = 'html', booktabs = T, escape = F) %>% + kableExtra::kable_styling("basic", full_width = F, position = 'left') %>% + kableExtra::column_spec(1, width_min = "1.5in") %>% + kableExtra::column_spec(2, width_min = "2.0in") %>% + kableExtra::column_spec(3, width_min = "2.5in") %>% + kableExtra::column_spec(4, width_min = "1.0in") + + } else "" +``` + +`r if ('Package Dependencies' %in% params$report_includes) {"Metrics whose score is NA will not impact the package {riskmetric} score"}` + +```{r package_dependencies_table} + if('Package Dependencies' %in% params$report_includes) { + kableExtra::kbl(params$dep_table, format = 'pipe') + } else "" +``` + + ```{r source_explorer_metrics} if(any(c('Source Explorer Comments') %in% params$report_includes)) { diff --git a/inst/report_downloads/reportHtml.Rmd b/inst/report_downloads/reportHtml.Rmd index ab17a2a0c..53d0a71c3 100644 --- a/inst/report_downloads/reportHtml.Rmd +++ b/inst/report_downloads/reportHtml.Rmd @@ -30,6 +30,8 @@ params: com_metrics: NA com_metrics_raw: NA downloads_plot_data: NA + dep_cards: NA + dep_table: NA metric_tbl: NA --- @@ -368,6 +370,28 @@ tagList( ``` +```{r package_dependencies} +tagList( + if('Package Dependencies' %in% params$report_includes) { + tagList( + br(), + hr(), + br(), + h5("Package Dependencies", style = "text-align: center;"), + br(), + createGrid(metrics = params$dep_cards), + br(), + DT::datatable(params$dep_table, + options = list(dom = "t", searching = FALSE, pageLength = -1, + lengthChange = FALSE, info = FALSE, + columnDefs = list(list(className = 'dt-center', targets = 2)))) + ) + + } else "" +) +``` + + ```{r source_explorer} tagList( if(any(c('Source Explorer Comments') %in% params$report_includes)) { @@ -429,7 +453,7 @@ tagList( strong('{riskassessment} App Version:'), br(), getElement(params, 'app_version'), br(), br(), strong('{riskmetric} Version:'), br(), getElement(params, 'riskmetric_version'), br(), br(), strong('Generated on:'), br(), format(Sys.time(), usetz = TRUE), br(), br(), - if('Risk Score' %in% params$report_includes) strong('Metric Weights:') else "" + if('Risk Score' %in% params$report_includes) tagList(hr(),br(),strong('Metric Weights:')) else "" ) if('Risk Score' %in% params$report_includes) { diff --git a/inst/report_downloads/reportPdf.Rmd b/inst/report_downloads/reportPdf.Rmd index 444f5ff56..e184dcbce 100644 --- a/inst/report_downloads/reportPdf.Rmd +++ b/inst/report_downloads/reportPdf.Rmd @@ -3,6 +3,7 @@ title: "R Package Risk Assessment" subtitle: "Report for Package: `r params$pkg[['name']]`" author: " `r if('Report Author' %in% params$report_includes) paste0('Author (Role): ', params$user_name, ' (', params$user_role, ')') else ''`" date: " `r if('Report Date' %in% params$report_includes) paste0('Report Date: ', format(Sys.time(), '%B %d, %Y')) else ''`" +geometry: "left=.5in,right=.5in,top=1.5in,bottom=1in" output: pdf_document: latex_engine: xelatex @@ -29,6 +30,8 @@ params: com_metrics: NA com_metrics_raw: NA downloads_plot_data: NA + dep_cards: NA + dep_table: NA metric_tbl: NA --- @@ -44,10 +47,13 @@ library(shiny) library(ggplot2) library(plotly) +options(tinytex.verbose = TRUE) knitr::opts_chunk$set(echo = F, fig.width = 5.5, fig.height = 3.4) cm_ind <- nrow(params$com_metrics) != 0 ``` + +`r {"\\setlength{\\headheight}{53.61403pt}\\addtolength{\\topmargin}{-38.61403pt}"}` ```{r functions, include=FALSE, message=FALSE, warning=FALSE} outputComments <- function(pkg_name, comments, none_txt = "No comments"){ @@ -67,7 +73,6 @@ outputComments <- function(pkg_name, comments, none_txt = "No comments"){ } ``` -
```{r general_pkg_info} tagList( @@ -100,6 +105,7 @@ if('Overall Comment' %in% params$report_includes){ } ``` + ```{r pkg_summary} if('Package Summary' %in% params$report_includes){ tagList( @@ -115,7 +121,7 @@ if('Package Summary' %in% params$report_includes){ } ``` -`r if(any(c('Maintenance Metrics', 'Maintenance Comments') %in% params$report_includes)) {"\\newpage"}` +`r if(any(c('Maintenance Metrics', 'Maintenance Comments') %in% params$report_includes)) {"\\newpage "}` ```{r maintenance_metrics} if(any(c('Maintenance Metrics', 'Maintenance Comments') %in% params$report_includes)) { @@ -124,33 +130,40 @@ if(any(c('Maintenance Metrics', 'Maintenance Comments') %in% params$report_inclu ``` -```{r maintenance_metrics_table, warning=FALSE, message=FALSE, error=FALSE, results='HIDE', echo=FALSE} +```{r maintenance_metrics_table, warning=FALSE, message=FALSE, error=FALSE, results='markdown', echo=FALSE} if('Maintenance Metrics' %in% params$report_includes){ - # maint_out_tab <- - params$maint_metrics %>% - dplyr::mutate( - `Metric Name` = title, - `Metric Description` = desc, - `Metric Value` = dplyr::case_when( - value %in% c("pkg_metric_error", "NA", NA) ~ "Not found", - # name %in% c('has_website', 'has_source_control') & nchar(value) > 5 ~ 'Yes', - # stringr::str_wrap(sub("\\s+$", "", gsub('(.{20})', '\\1 ', value)), 20), # text-wrap - value %in% c("TRUE","1") ~ 'Yes', - !(name %in% c('has_bug_reports_url', 'news_current')) ~ value, - TRUE ~ 'No' - ), - `Metric Score` = dplyr::case_when(toupper(score) %in% c("NA", "NULL") ~ "NA", - # flip the label display of the score to mimic the package score... - round(as.numeric(score), 2) == 0 ~ "1.0", - round(as.numeric(score), 2) == 1 ~ "0.0", - TRUE ~ as.character(round(1 - as.numeric(score), 2)) - ) - ) %>% - dplyr::select(`Metric Name`, `Metric Description`, `Metric Value`, `Metric Score`) %>% - knitr::kable(format = 'pandoc') +params$maint_metrics %>% + dplyr::mutate( + `Metric Name` = title, + `Metric Description` = desc, + `Metric Value` = dplyr::case_when( + value %in% c("pkg_metric_error", "NA", NA) ~ "Not found", + value %in% c("TRUE","1") ~ 'Yes', + !(name %in% c('has_bug_reports_url', 'news_current')) ~ value, + TRUE ~ 'No' + ), + score = na_if(score, "NA"), + score = na_if(score, "NULL"), + `Metric Score` = dplyr::case_when(toupper(score) %in% c("NA", "NULL") ~ NA_character_, + # flip the label display of the score to mimic the package score... + round(as.numeric(score), 2) == 0 ~ "1.0", + round(as.numeric(score), 2) == 1 ~ "0.0", + TRUE ~ as.character(round(1 - as.numeric(score), 2)) + ) + ) %>% + # add a space after the .com + dplyr::mutate(`Metric Value` = stringr::str_replace(`Metric Value`, stringr::regex("^(.+\\.com\\/)"), "\\1 ")) %>% + dplyr::select(`Metric Name`, `Metric Description`, `Metric Value`, `Metric Score`) %>% + kableExtra::kbl(format = 'latex', booktabs = T, linesep = "") %>% + kableExtra::kable_styling("basic", latex_options = "hold_position", full_width = F, position = 'left') %>% + kableExtra::column_spec(1, width = "1.0in") %>% + kableExtra::column_spec(2, width = "2.0in", latex_valign = "p") %>% + kableExtra::column_spec(3, width = "2.0in", latex_valign = "p") %>% + kableExtra::column_spec(4, width = "0.75in") } ``` -`r if ('Maintenance Metrics' %in% params$report_includes) {"* Metrics whose score is NA will not impact the package {riskmetric} score"}` + +`r if ('Maintenance Metrics' %in% params$report_includes) {"Metrics whose score is NA will not impact the package {riskmetric} score"}` ```{r maintenance_metrics_comments} if('Maintenance Comments' %in% params$report_includes){ @@ -165,7 +178,7 @@ if('Maintenance Comments' %in% params$report_includes){ ``` -`r if(any(c('Community Usage Metrics', 'Community Usage Comments') %in% params$report_includes)) {"\\newpage"}` +`r if(any(c('Community Usage Metrics', 'Community Usage Comments') %in% params$report_includes)) {"\\newpage "}` ```{r community_metrics, warning=FALSE, message=FALSE} if(any(c('Community Usage Metrics', 'Community Usage Comments') %in% params$report_includes)) { @@ -174,7 +187,7 @@ if(any(c('Community Usage Metrics', 'Community Usage Comments') %in% params$repo ``` -```{r community_metrics_table, warning=FALSE, message=FALSE, error=FALSE, results='HIDE', echo=FALSE} +```{r community_metrics_table, warning=FALSE, message=FALSE, error=FALSE, results='markdown', echo=FALSE} if (!cm_ind) { h6(glue::glue("Community Usage Metrics not avaiable for {params$pkg$name}"), style = "text-align: center; color: gray; padding-top: 50px;") @@ -182,10 +195,12 @@ if (!cm_ind) { if('Community Usage Metrics' %in% params$report_includes){ params$com_metrics %>% dplyr::mutate( + score = na_if(score, "NA"), + score = na_if(score, "NULL"), `Metric Name` = title, `Metric Description` = desc, `Metric Value` = ifelse(value %in% c("pkg_metric_error", "NA", NA), "Not found", value), - `Metric Score` = dplyr::case_when(toupper(score) %in% c("NA", "NULL") ~ "NA", + `Metric Score` = dplyr::case_when(toupper(score) %in% c("NA", "NULL") ~ NA_character_, # flip the label display of the score to mimic the package score... round(as.numeric(score), 2) == 0 ~ "1.0", round(as.numeric(score), 2) == 1 ~ "0.0", @@ -193,11 +208,13 @@ if (!cm_ind) { ) ) %>% dplyr::select(`Metric Name`, `Metric Description`, `Metric Value`, `Metric Score`) %>% - knitr::kable(format = 'pandoc') + kableExtra::kbl(format = 'latex', booktabs = T, linesep = "") %>% + kableExtra::kable_styling("basic", latex_options = "hold_position", full_width = F, position = 'left') } } ``` -`r if ('Community Usage Metrics' %in% params$report_includes) {"* Metrics whose score is NA will not impact the package {riskmetric} score"}` + +`r if ('Community Usage Metrics' %in% params$report_includes) {"Metrics whose score is NA will not impact the package {riskmetric} score"}` ```{r community_metrics_plot_title, eval=cm_ind} @@ -246,9 +263,50 @@ if('Community Usage Comments' %in% params$report_includes){ } ``` +`r if('Package Dependencies' %in% params$report_includes) {"\\newpage "}` + +```{r package_dependencies_header} + if('Package Dependencies' %in% params$report_includes) { + tagList(br(), h2("Package Dependencies"), br()) + } else "" +``` + +```{r package_dependencies_cards} + if('Package Dependencies' %in% params$report_includes) { + cards <- params$dep_cards %>% + dplyr::mutate( + score = na_if(score, "NA"), + score = na_if(score, "NULL"), + `Metric Name` = title, + `Metric Description` = desc, + `Metric Value` = ifelse(value %in% c("pkg_metric_error", "NA", NA), "Not found", value), + `Metric Score` = dplyr::case_when(toupper(score) %in% c("NA", "NULL") ~ "NA", + # flip the label display of the score to mimic the package score... + round(as.numeric(score), 2) == 0 ~ "1.0", + round(as.numeric(score), 2) == 1 ~ "0.0", + TRUE ~ as.character(round(1 - as.numeric(score), 2)) + ) + ) %>% + dplyr::select(`Metric Name`, `Metric Description`, `Metric Value`, `Metric Score`) + + kableExtra::kbl(cards, format = 'latex', booktabs = T, linesep = "") %>% + kableExtra::kable_styling("basic", latex_options = "hold_position", full_width = F, position = 'left') %>% + kableExtra::column_spec(3, width = "1.5in", latex_valign = "p") + + } else "" +``` + +`r if ('Package Dependencies' %in% params$report_includes) {"Metrics whose score is NA will not impact the package {riskmetric} score"}` +```{r package_dependencies_table} + if('Package Dependencies' %in% params$report_includes) { + params$dep_table %>% + kableExtra::kbl(format = 'latex', booktabs = T, linesep = "") %>% + kableExtra::kable_styling("basic", latex_options = "hold_position", full_width = F, position = 'left') + } else "" +``` -`r if(any(c('Source Explorer Comments') %in% params$report_includes)) {"\\newpage"}` +`r if(any(c('Source Explorer Comments') %in% params$report_includes)) {"\\newpage "}` ```{r source_explorer} if(any(c('Source Explorer Comments') %in% params$report_includes)) { @@ -272,9 +330,7 @@ if('Source Explorer Comments' %in% params$report_includes){ } ``` - - -`r if(any(c('Function Explorer Comments') %in% params$report_includes)) {"\\newpage"}` +`r if(any(c('Function Explorer Comments') %in% params$report_includes)) {"\\newpage "}` ```{r function_explorer} if(any(c('Function Explorer Comments') %in% params$report_includes)) { @@ -298,13 +354,13 @@ if('Function Explorer Comments' %in% params$report_includes){ } ``` -\newpage +`r {"\\newpage "}` ```{r about_report_title} tagList(br(), h2('About The Report')) ``` -```{r about_report} +```{r about_report, warning=FALSE} tagList( strong('{riskassessment} App Version:'), br(), getElement(params, 'app_version'), br(), br(), @@ -314,11 +370,9 @@ tagList( ) if('Risk Score' %in% params$report_includes) { - tab_out <- params$metric_weights %>% - knitr::kable(align = c('l','c'), format = 'latex', booktabs = TRUE) - - if (!requireNamespace("kableExtra", quietly = TRUE)) tab_out else tab_out %>% kableExtra::kable_styling(position = "left") + kableExtra::kbl(booktabs = TRUE, linesep = "", format = "latex", align = c('l','c'), centering = F) %>% + kableExtra::kable_styling(position = "left") } ``` diff --git a/man/databaseViewServer.Rd b/man/databaseViewServer.Rd index a41596c0f..58ddeea39 100644 --- a/man/databaseViewServer.Rd +++ b/man/databaseViewServer.Rd @@ -4,7 +4,16 @@ \alias{databaseViewServer} \title{Server logic for 'Database View' module} \usage{ -databaseViewServer(id, user, uploaded_pkgs, metric_weights, changes, parent) +databaseViewServer( + id, + user, + uploaded_pkgs, + metric_weights, + dep_metrics, + loaded2_db, + changes, + parent +) } \arguments{ \item{id}{a module id name} @@ -15,6 +24,10 @@ databaseViewServer(id, user, uploaded_pkgs, metric_weights, changes, parent) \item{metric_weights}{a reactive data.frame holding metric weights} +\item{dep_metrics}{placeholder} + +\item{loaded2_db}{placeholder} + \item{changes}{a reactive value integer count} \item{parent}{the parent (calling module) session information} diff --git a/man/packageDependenciesServer.Rd b/man/packageDependenciesServer.Rd index a6e959c98..7930acb52 100644 --- a/man/packageDependenciesServer.Rd +++ b/man/packageDependenciesServer.Rd @@ -4,13 +4,15 @@ \alias{packageDependenciesServer} \title{Package Dependencies module's server logic} \usage{ -packageDependenciesServer(id, selected_pkg, user, parent) +packageDependenciesServer(id, selected_pkg, loaded2_db, user, parent) } \arguments{ \item{id}{a module id name} \item{selected_pkg}{placeholder} +\item{loaded2_db}{placeholder} + \item{user}{placeholder} \item{parent}{the parent (calling module) session information} diff --git a/man/reportPreviewServer.Rd b/man/reportPreviewServer.Rd index 7e99c8684..06c321003 100644 --- a/man/reportPreviewServer.Rd +++ b/man/reportPreviewServer.Rd @@ -13,6 +13,8 @@ reportPreviewServer( mm_comments, cm_comments, downloads_plot_data, + dep_metrics, + loaded2_db, user, credentials, app_version, @@ -36,6 +38,10 @@ reportPreviewServer( \item{downloads_plot_data}{placeholder} +\item{dep_metrics}{placeholder} + +\item{loaded2_db}{placeholder} + \item{user}{placeholder} \item{app_version}{placeholder} diff --git a/tests/testthat/_snaps/databaseView/003.json b/tests/testthat/_snaps/databaseView/003.json index cb5559919..884f05029 100644 --- a/tests/testthat/_snaps/databaseView/003.json +++ b/tests/testthat/_snaps/databaseView/003.json @@ -14,7 +14,7 @@ "1.1.2" ], "score": [ - 0.3, + 0.25, 0.27 ], "decision": [ diff --git a/tests/testthat/test-apps/downloadHandler-app/app.R b/tests/testthat/test-apps/downloadHandler-app/app.R index 9d34723c1..449869f29 100644 --- a/tests/testthat/test-apps/downloadHandler-app/app.R +++ b/tests/testthat/test-apps/downloadHandler-app/app.R @@ -35,8 +35,36 @@ server <- function(input, output, session) { class = "data.frame", row.names = c(NA, -12L))) - riskassessment:::mod_downloadHandler_server("downloadHandler_1", pkg, user, metric_weights) - riskassessment:::mod_downloadHandler_server("downloadHandler_2", pkgs, user, metric_weights) + loaded2_db <- eventReactive(pkg(), { + + dbSelect("SELECT name, version, score FROM package") + }) + + # Get Package Dependency metrics. + dep_metrics <- reactiveVal() + + pkgref <- eventReactive(pkg(), { + + get_assess_blob(pkg()) + }) + + observeEvent(pkgref(), { + req(pkgref()) + tryCatch( + expr = { + dep_metrics(pkgref()$dependencies[[1]] %>% dplyr::as_tibble()) + }, + error = function(e) { + msg <- paste("Detailed dependency information is not available for package", selected_pkg$name()) + rlang::warn(msg) + rlang::warn(paste("info:", e)) + dep_metrics(dplyr::tibble(package = character(0), type = character(0), name = character(0))) + } + ) + }) + + riskassessment:::mod_downloadHandler_server("downloadHandler_1", pkg, user, metric_weights, dep_metrics, loaded2_db) + riskassessment:::mod_downloadHandler_server("downloadHandler_2", pkgs, user, metric_weights, dep_metrics, loaded2_db) } shinyApp(ui, server) diff --git a/tests/testthat/test-reportPreview.R b/tests/testthat/test-reportPreview.R index 8c0a8b58f..3e3d4ddbe 100644 --- a/tests/testthat/test-reportPreview.R +++ b/tests/testthat/test-reportPreview.R @@ -61,7 +61,7 @@ test_that("Reactivity of reportPreview", { rvest::html_text() %>% paste(collapse = ", ") - str_expect <- "Vignettes, Report Bugs, Source Control, License, NEWS file, Website, Documentation, Dependencies, NEWS current, Maintainer, Bugs Closure Rate, Test Coverage, First Version Release*, Reverse Dependencies, Latest Version Release*, Monthly downloads trend*, Package Downloads" + str_expect <- "Vignettes, Report Bugs, Source Control, License, NEWS file, Website, Documentation, Dependencies, NEWS current, Maintainer, Bugs Closure Rate, Test Coverage, First Version Release*, Reverse Dependencies, Latest Version Release*, Monthly downloads trend*, Package Downloads, Dependencies Uploaded*, Type Summary*, Base R Summary*" expect_equal(maint_info, str_expect) app$stop()