Skip to content

Commit

Permalink
Merge pull request #803 from pharmaR/ac-802
Browse files Browse the repository at this point in the history
Bug fix preventing Pkg Deps tab from crashing when dep info not available
  • Loading branch information
jthompson-arcus authored Jul 9, 2024
2 parents 10690d0 + 32c3137 commit bd8001c
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 48 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: riskassessment
Title: A web app designed to interface with the `riskmetric` package
Version: 3.1.0.9001
Version: 3.1.1
Authors@R: c(
person("Aaron", "Clark", role = c("aut", "cre"), email = "[email protected]"),
person("Jeff", "Thompson", role = c("aut"), email = "[email protected]", comment = "Co-Lead"),
Expand Down
3 changes: 2 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# riskassessment (development version)
# riskassessment 3.1.1

* Added navigation controls in Function Explorer tab (#644)
* Fixed bug that crashed the Package Dependencies page for pkgs without any dependency info available (#802)

# riskassessment 3.1.0

Expand Down
8 changes: 4 additions & 4 deletions R/mod_packageDependencies.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ packageDependenciesServer <- function(id, selected_pkg, user, credentials, paren
req(pkgref())
tryCatch(
expr = {
deep_ends <- pkgref()$dependencies[[1]] %>% dplyr::as_tibble() %>%
deep_ends <- {if(suppressWarnings(is.null(nrow(pkgref()$dependencies[[1]])) || nrow(pkgref()$dependencies[[1]]) == 0)) dplyr::tibble(package = character(0), type = character(0)) else pkgref()$dependencies[[1]] %>% dplyr::as_tibble()} %>%
mutate(package = stringr::str_replace(package, "\n", " ")) %>%
mutate(name = stringr::str_extract(package, "^((([[A-z]]|[.][._[A-z]])[._[A-z0-9]]*)|[.])"))

Expand Down Expand Up @@ -94,7 +94,8 @@ packageDependenciesServer <- function(id, selected_pkg, user, credentials, paren
)
tryCatch(
expr = {
shrug_jests <- pkgref()$suggests[[1]] %>% dplyr::as_tibble()%>%
shrug_jests <-
{if(suppressWarnings(is.null(nrow(pkgref()$suggests[[1]])) || nrow(pkgref()$suggests[[1]]) == 0)) dplyr::tibble(package = character(0), type = character(0)) else pkgref()$suggests[[1]] %>% dplyr::as_tibble()} %>%
mutate(package = stringr::str_replace(package, "\n", " ")) %>%
mutate(name = stringr::str_extract(package, "^((([[A-z]]|[.][._[A-z]])[._[A-z0-9]]*)|[.])"))

Expand Down Expand Up @@ -122,8 +123,7 @@ packageDependenciesServer <- function(id, selected_pkg, user, credentials, paren
decision_id = character(0)))
}
)
# this is so the dependencies is also a 0x2 tibble like suggests
if (rlang::is_empty(pkgref()$dependencies[[1]])) depends(dplyr::tibble(package = character(0), type = character(0), name = character(0)))


revdeps(pkgref()$reverse_dependencies[[1]] %>% as.vector())

Expand Down
1 change: 0 additions & 1 deletion R/utils_build_cards.R
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,6 @@ build_dep_cards <- function(data, loaded, toggled){
is_url = numeric(),
type = character()
)


deps <- data %>%
mutate(base = if_else(name %in% c(rownames(installed.packages(priority = "base"))), "Base", "Non-Base")) %>%
Expand Down
72 changes: 37 additions & 35 deletions R/utils_get_db.R
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,42 @@ get_metric_data <- function(pkg_name, metric_class = 'maintenance', db_name = go
)
}

#' Get Dependency Pkg Versions and Scores
#'
#'
#' @param pkg_name character name of the package
#' @param verify_data a data.frame used to verify whether a pkg exists in the db
#' @param cran_pkgs a data.frame containing all available cran package names/versions
#'
#' @returns a list
#' @noRd
get_versnScore <- function(pkg_name, verify_data, cran_pkgs) {

if (rlang::is_empty(pkg_name))
return(list(name = character(), version = character(), score = character(),
decision_id = character(), decision = character()))

if (pkg_name %in% verify_data$name) { #loaded2_db()$name
tmp_df <- verify_data %>% filter(name == pkg_name) %>% select(score, version, decision_id, decision)
pkg_score <- tmp_df %>% pull(score) %>% as.character
pkg_versn <- tmp_df %>% pull(version) %>% as.character
pkg_decision_id <- tmp_df %>% pull(decision_id) %>% as.character
pkg_decision <- tmp_df %>% pull(decision) %>% as.character
} else {
pkg_score <- ""
pkg_versn <- if_else(pkg_name %in% c(rownames(installed.packages(priority="base"))), "",
subset(cran_pkgs, Package == pkg_name, c("Version")) %>% as.character())
pkg_decision_id <- ""
pkg_decision <- ""
}

return(list(name = pkg_name, version = pkg_versn, score = pkg_score,
decision_id = pkg_decision_id, decision = pkg_decision
))
}



#' The 'Get Dependencies Metrics Data' function
#'
#' Pull the depenencies data for a specific package id, and create
Expand Down Expand Up @@ -277,7 +313,7 @@ get_depends_data <- function(pkg_name,
deps_decision_data <- purrr::map_df(deep_ends$name, ~get_versnScore(.x, loaded2_db, repo_pkgs))
if(nrow(deps_decision_data) == 0) {
deps_w_decision <- dplyr::tibble(name = character(0), version = character(0),
score = character(0), decision = character(0), decision_id = character(0))
score = character(0), decision = character(0), decision_id = character(0))
} else {
deps_w_decision <- deps_decision_data
}
Expand Down Expand Up @@ -407,40 +443,6 @@ get_assess_blob <- function(pkg_lst, db_name = golem::get_golem_options('assessm
}


#' Get Dependency Pkg Versions and Scores
#'
#'
#' @param pkg_name character name of the package
#' @param verify_data a data.frame used to verify whether a pkg exists in the db
#' @param cran_pkgs a data.frame containing all available cran package names/versions
#'
#' @returns a list
#' @noRd
get_versnScore <- function(pkg_name, verify_data, cran_pkgs) {

if (rlang::is_empty(pkg_name))
return(list(name = character(), version = character(), score = character(),
decision_id = character(), decision = character()))

if (pkg_name %in% verify_data$name) { #loaded2_db()$name
tmp_df <- verify_data %>% filter(name == pkg_name) %>% select(score, version, decision_id, decision)
pkg_score <- tmp_df %>% pull(score) %>% as.character
pkg_versn <- tmp_df %>% pull(version) %>% as.character
pkg_decision_id <- tmp_df %>% pull(decision_id) %>% as.character
pkg_decision <- tmp_df %>% pull(decision) %>% as.character
} else {
pkg_score <- ""
pkg_versn <- if_else(pkg_name %in% c(rownames(installed.packages(priority="base"))), "",
subset(cran_pkgs, Package == pkg_name, c("Version")) %>% as.character())
pkg_decision_id <- ""
pkg_decision <- ""
}

return(list(name = pkg_name, version = pkg_versn, score = pkg_score,
decision_id = pkg_decision_id, decision = pkg_decision
))
}



##### End of get_* functions #####
Expand Down
12 changes: 6 additions & 6 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4367,7 +4367,7 @@
"Maintainer": "Kevin Ushey <[email protected]>",
"Repository": "RSPM",
"Date/Publication": "2024-02-29 01:10:07 UTC",
"Built": "R 4.3.3; ; 2024-07-08 12:36:44 UTC; unix"
"Built": "R 4.3.3; ; 2024-07-09 14:01:48 UTC; unix"
}
},
"reprex": {
Expand Down Expand Up @@ -6220,7 +6220,7 @@
"checksum": "99c5575cb81828e20a7fe1d205551316"
},
"DESCRIPTION": {
"checksum": "ea81f750b1ae3fa6b3ebf79e5668a3ee"
"checksum": "43f16dae5ba2122f4fd55e23f7229a40"
},
"inst/app/www/css/community_metrics.css": {
"checksum": "f08eb25c2ee48ac22ed63b0d18994a04"
Expand Down Expand Up @@ -6463,7 +6463,7 @@
"checksum": "97d1232340e04c53088bc8f814133dcd"
},
"NEWS.md": {
"checksum": "29db451dbb57771e940e1911eac5407f"
"checksum": "72bdae63c42eb2750d86e97fc0996a79"
},
"R/app_config.R": {
"checksum": "c2b61f270b86b6833f0ee39c44a1a440"
Expand Down Expand Up @@ -6532,7 +6532,7 @@
"checksum": "a894eb9114e258feb99b76cdca557cd2"
},
"R/mod_packageDependencies.R": {
"checksum": "6fffb51829775826e242824f268062b6"
"checksum": "f8cee3c4845b4d3c3c2f66796af28359"
},
"R/mod_pkg_explorer_utils.R": {
"checksum": "b7792e08cc4a67296c9df0f452c0a72a"
Expand Down Expand Up @@ -6565,13 +6565,13 @@
"checksum": "e5835b81f48d93ee0175507abbb3186f"
},
"R/utils_build_cards.R": {
"checksum": "f79316fe637bb1f4038f085621d298f5"
"checksum": "a7cfdc1f9a4ad1c2835cd22eb279d8dc"
},
"R/utils_config_db.R": {
"checksum": "74cf2ee5e7283483a88f08d60e3728b0"
},
"R/utils_get_db.R": {
"checksum": "6e87d4d43f93b4a4b556d72b848dc3f1"
"checksum": "6c0e6fb4b3716cdd0c0d2953a1cf4393"
},
"R/utils_insert_db.R": {
"checksum": "2c02e4eab4d9262ef8c8e64eb0f1b4f5"
Expand Down

0 comments on commit bd8001c

Please sign in to comment.