pharmaR / riskmetric

Metrics to evaluate the risk of R packages
https://pharmar.github.io/riskmetric/
Other
156 stars 29 forks source link

Fix #287 - Document metrics available by source #313

Closed parmsam-pfizer closed 7 months ago

parmsam-pfizer commented 9 months ago
parmsam-pfizer commented 9 months ago

@emilliman5 Can you share the code you used to generate the generic calls by dispatch source in this video? Did you use the code you already shared in #287?

emilliman5 commented 9 months ago

@AARON-CLARK, should we create a function to generate a table of available assessments and metrics by ref source or would a rendered vignette be sufficient?

emilliman5 commented 9 months ago

@parmsam-pfizer here is the code to create a rudimentary table linking assessments to ref source.

ns <- getNamespaceExports("riskmetric")

ns <- grep("^pkg_ref_cache|^assess_", ns, value = T, 
           ignore.case = T)
ns <- sapply(ns, methods)

ns_df <- tibble(export=unlist(ns)) %>%
  bind_rows(tibble(export=names(ns)[sapply(ns, length)==0])) %>% 
  separate(export, c("generic", "cache", "class"), 
           sep = "\\.", remove = F)

ns_df %>% filter(grepl("assess", generic)) %>%
  select(generic, class=cache) %>%
  mutate(value=1) %>%
  pivot_wider(names_from = class, values_from = value) %>% 
  mutate(default = coalesce(default, `NA`)) %>% 
  select(generic, default, everything(), -`NA`)
AARON-CLARK commented 9 months ago

Hi all, honestly, I think that either would be a step in the right direction although I admit building a function would be more work. If you just wanted to start with a vignette, that works for me. However, I would think that a function would be the most robust solution because it offers the highest value proposition to the most people:

  1. Users could extract this info during a session, helping them choose a source. For example, if someone really cares about metric xyz, I envision the function could help them identify which pkg sources support that assessment. Conversely, if all they can do is use a particular source, like "pkg_cran_remote", then they can see which assessments they're restricted to. This data would be helpful to display in the riskassessment app too. The app doesn't yet support pkg_source, but it we do untar source files now, so it's a possibility in the near future. When that time comes, we'd want to make the user choose their source arg, so equipping them with assessment coverage info from this function would be helpful. I realize we could also scrape the info from the pkgdown site, but using a function is cleaner and able to help more users (besides just the riskassessment dev team).

  2. riskmetric developers could potentially use it for pkg dev logic. Perhaps it'd come in handy when working on #299? Or maybe it could inform how riskmetric generates output? For example, if metric xyz isn't available for "pkg_cran_remote", then why show it? The proposed function could tell riskmetric what should be reported instead of showing NA for the unsupported metrics. That suggestion may be outlandish, but it's just an example of what the function could do, if it existed.

  3. The function's output could also get sucked into a vignette, helping users learn about riskmetric through via it's docs.

parmsam commented 9 months ago

Pasting this reference table code from personal Github for a later commit:

library(riskmetric)
library(dplyr)
library(tibble)
library(tidyr)
library(gt)
library(gtExtras)

ns <- getNamespaceExports("riskmetric")

ns <- grep("^pkg_ref_cache|^assess_", ns, value = T, 
           ignore.case = T)
ns <- sapply(ns, methods)

ns_df <- tibble(export=unlist(ns)) %>%
  bind_rows(tibble(export=names(ns)[sapply(ns, length)==0])) %>% 
  separate(export, c("generic", "cache", "class"), 
           sep = "\\.", remove = F)

cross_tbl <- ns_df %>% filter(grepl("assess", generic)) %>%
  select(generic, class=cache) %>%
  mutate(value=1) %>%
  pivot_wider(names_from = class, values_from = value) %>% 
  mutate(default = coalesce(default, `NA`)) %>% 
  select(generic, default, everything(), -`NA`)

cross_tbl %>% 
  mutate(
    across(c(everything(), -generic), 
           function(x) ifelse(is.na(x), "square-xmark", "square-check"))
  ) %>%
  gt() %>%
  gt_fa_column(
    column = c(everything(), -generic),
    palette = c(
      "square-check" = "#009E73", 
      "square-xmark" = "#D55E00"
    )
  )