pharmaR / riskmetric

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

pkg_assess() returns different object types when assessing 1 package vs. >1 package #342

Open fh-kpikhart opened 2 months ago

fh-kpikhart commented 2 months ago

It would be helpful if pkg_assess() always returned a tibble in order to be able to programmatically manipulate the outputs, but when only 1 pkg_ref is passed in, it returns a list.

library(dplyr)
library(riskmetric)
packageVersion("riskmetric")

[1] ‘0.2.4’

# Assessing >1 packages gives a tibble
c("dplyr", "ggplot2") %>%
  pkg_ref(source = "pkg_cran_remote", repos = c("https://cran.rstudio.com")) %>%
  pkg_assess(all_assessments[1:2])

# A tibble: 2 × 5
  package version pkg_ref              bugs_status covr_coverage
  <chr>   <chr>   <lst_f_p_>           <lst_f_p_>  <lst_f_p_>   
1 dplyr   1.1.4   dplyr<cran_remote>   <error>     NA           
2 ggplot2 3.5.1   ggplot2<cran_remote> <error>     NA 

# Assessing 1 package gives a list
c("dplyr") %>%
  pkg_ref(source = "pkg_cran_remote", repos = c("https://cran.rstudio.com")) %>%
  pkg_assess(all_assessments[1:2])

<list_of_pkg_metric[2]>
$bugs_status
 [1] FALSE FALSE FALSE  TRUE FALSE FALSE  TRUE FALSE FALSE FALSE  TRUE FALSE  TRUE FALSE  TRUE FALSE FALSE  TRUE
[19] FALSE  TRUE  TRUE  TRUE  TRUE  TRUE FALSE FALSE FALSE FALSE  TRUE  TRUE

$covr_coverage
[1] NA
attr(,"class")
[1] "pkg_metric_na"            "pkg_metric_condition"     "pkg_metric_covr_coverage" "pkg_metric"              
[5] "logical"                 
attr(,"label")
[1] "Package unit test coverage"
emilliman5 commented 1 month ago

We have discussed this and it has been brought up in directly #231. My preference would be to always return a list of lists and provide an as_tibble method to easily coerce. a list of list, IMHO, is a more natural representation of assessments than a df (vectors and dfs, nested in side columns of a df is not m favorite). By extension we should also return the same object type for scores, in this case a df makes sense, as it is one value per colomn.