From 1203d99016748c441dec77aa99d1f03c3028b1e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Th=C3=A9riault?= <13123390+rempsyc@users.noreply.github.com> Date: Sat, 9 Mar 2024 21:31:36 +0100 Subject: [PATCH] closes #1 --- DESCRIPTION | 15 ++++++++------- R/dygraph_year.R | 1 + R/render_dashboard.R | 1 + R/scatter_continent_year.R | 2 ++ R/scatter_country_year.R | 1 + R/scatter_figure1.R | 2 ++ R/table_continent.R | 1 + R/table_continent_journal.R | 1 + R/table_continent_year.R | 1 + R/table_country.R | 1 + R/table_country_journal.R | 1 + R/table_country_year.R | 1 + R/table_missing_country.R | 1 + R/waffle_continent.R | 1 + R/waffle_continent_journal.R | 1 + R/waffle_country.R | 1 + R/waffle_country_journal.R | 1 + 17 files changed, 26 insertions(+), 7 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index fd254d3..d16c9fb 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -7,30 +7,31 @@ Authors@R: Description: Package to facilitate the creation of data visualization dashboards through the flexdashboard and easyPubMed packages. License: GPL (>= 3) -Suggests: - testthat (>= 3.0.0) Imports: easyPubMed, rempsyc, + insight, dplyr, rlang, purrr, stringr, stringi, - countrycode, + countrycode, Ecfun, lubridate, + tidyr +Suggests: ggplot2, - ggflags (>= 0.0.3), + RColorBrewer, DT, waffle (>= 1.0.1), - tidyr, + ggflags (>= 0.0.3), plotly, - RColorBrewer, dygraphs, xts, rstudioapi, - rmarkdown + rmarkdown, + testthat (>= 3.0.0) Config/testthat/edition: 3 Encoding: UTF-8 Roxygen: list(markdown = TRUE) diff --git a/R/dygraph_year.R b/R/dygraph_year.R index 59dcd33..79fc4bb 100644 --- a/R/dygraph_year.R +++ b/R/dygraph_year.R @@ -29,6 +29,7 @@ #' @export dygraph_year <- function(data, level = "continent") { + insight::check_if_installed(c("dygraphs", "xts")) df_country_year <- data %>% dplyr::group_by(.data$year, .data[[level]]) %>% dplyr::filter(!is.na(.data[[level]])) %>% diff --git a/R/render_dashboard.R b/R/render_dashboard.R index c120ea8..7e547b7 100644 --- a/R/render_dashboard.R +++ b/R/render_dashboard.R @@ -67,6 +67,7 @@ render_dashboard <- function(file_name = "dashboard", tab_general = FALSE, tab_figure1 = FALSE, tab_missing = TRUE) { + insight::check_if_installed(c("rstudioapi", "rmarkdown")) rmarkdown::render(system.file("dashboard.Rmd", package = "pubmedDashboard"), output_dir = getwd(), output_file = file_name diff --git a/R/scatter_continent_year.R b/R/scatter_continent_year.R index ebc26b5..ca3a979 100644 --- a/R/scatter_continent_year.R +++ b/R/scatter_continent_year.R @@ -28,6 +28,7 @@ #' @export scatter_continent_year <- function(data, method = "lm", plotly = TRUE) { + insight::check_if_installed("RColorBrewer") data <- data %>% dplyr::mutate(missing = sum(is.na(.data$continent)) / dplyr::n()) %>% dplyr::filter(!is.na(.data$continent)) %>% @@ -67,6 +68,7 @@ scatter_continent_year <- function(data, method = "lm", plotly = TRUE) { ) if (isTRUE(plotly)) { + insight::check_if_installed("plotly") x <- plotly::ggplotly(tooltip = c("x", "y")) } diff --git a/R/scatter_country_year.R b/R/scatter_country_year.R index de09c9a..058d61e 100644 --- a/R/scatter_country_year.R +++ b/R/scatter_country_year.R @@ -70,6 +70,7 @@ scatter_country_year <- function(data, method = "lm", plotly = TRUE) { ) if (isTRUE(plotly)) { + insight::check_if_installed("plotly") x <- plotly::ggplotly(tooltip = c("x", "y")) } diff --git a/R/scatter_figure1.R b/R/scatter_figure1.R index f7f5242..abb0290 100644 --- a/R/scatter_figure1.R +++ b/R/scatter_figure1.R @@ -33,6 +33,7 @@ #' @export scatter_figure1 <- function(data, method = "lm", original = TRUE, plotly = TRUE) { + insight::check_if_installed("ggplot2") df_journal_year <- data %>% dplyr::filter(!is.na(.data$country)) %>% dplyr::group_by(.data$year, .data$journal) %>% @@ -106,6 +107,7 @@ scatter_figure1 <- function(data, method = "lm", original = TRUE, plotly = TRUE) if (isTRUE(plotly)) { + insight::check_if_installed("plotly") fig1 <- plotly::ggplotly(fig1, tooltip = c("x", "y")) } diff --git a/R/table_continent.R b/R/table_continent.R index 3a1da68..efbb439 100644 --- a/R/table_continent.R +++ b/R/table_continent.R @@ -46,6 +46,7 @@ table_continent <- function(data, datatable = TRUE) { dplyr::rename_with(stringr::str_to_title) %>% dplyr::rename("Missing*" = "Missing") if (isTRUE(datatable)) { + insight::check_if_installed("DT") x <- DT::datatable(x, options = list(searching = FALSE, paging = FALSE), caption = "Journal paper percentages, by continent" diff --git a/R/table_continent_journal.R b/R/table_continent_journal.R index 106f7f5..fc91f5f 100644 --- a/R/table_continent_journal.R +++ b/R/table_continent_journal.R @@ -64,6 +64,7 @@ table_continent_journal <- function(data, datatable = TRUE) { dplyr::rename_with(stringr::str_to_title) if (isTRUE(datatable)) { + insight::check_if_installed("DT") x <- DT::datatable( x, options = list(iDisplayLength = 5), diff --git a/R/table_continent_year.R b/R/table_continent_year.R index eb78679..4f8553a 100644 --- a/R/table_continent_year.R +++ b/R/table_continent_year.R @@ -66,6 +66,7 @@ table_continent_year <- function(data, datatable = TRUE) { dplyr::rename_with(stringr::str_to_title) if (isTRUE(datatable)) { + insight::check_if_installed("DT") x <- DT::datatable(x, caption = "Journal paper percentages, by continent and year" ) diff --git a/R/table_country.R b/R/table_country.R index caa08f3..092747e 100644 --- a/R/table_country.R +++ b/R/table_country.R @@ -45,6 +45,7 @@ table_country <- function(data, datatable = TRUE) { dplyr::rename("Country Code" = "Country_code") if (isTRUE(datatable)) { + insight::check_if_installed("DT") x <- DT::datatable(x, caption = "Journal paper percentages, by country" ) diff --git a/R/table_country_journal.R b/R/table_country_journal.R index 1b38ff9..79cd0bf 100644 --- a/R/table_country_journal.R +++ b/R/table_country_journal.R @@ -59,6 +59,7 @@ table_country_journal <- function(data, datatable = TRUE) { dplyr::rename_with(stringr::str_to_title) if (isTRUE(datatable)) { + insight::check_if_installed("DT") x <- DT::datatable(x, caption = "Journal paper percentages, by country and journal" ) diff --git a/R/table_country_year.R b/R/table_country_year.R index 7aa083d..a805b35 100644 --- a/R/table_country_year.R +++ b/R/table_country_year.R @@ -55,6 +55,7 @@ table_country_year <- function(data, datatable = TRUE) { dplyr::arrange(dplyr::desc(.data$year), dplyr::desc(.data$Papers)) if (isTRUE(datatable)) { + insight::check_if_installed("DT") x <- DT::datatable(x, caption = "Journal paper percentages, by country and year" ) diff --git a/R/table_missing_country.R b/R/table_missing_country.R index 46570da..f60aa10 100644 --- a/R/table_missing_country.R +++ b/R/table_missing_country.R @@ -36,6 +36,7 @@ table_missing_country <- function(data, datatable = TRUE) { dplyr::mutate(doi = paste0("", .data$doi, "")) if (isTRUE(datatable)) { + insight::check_if_installed("DT") x <- DT::datatable(x, extensions = "Responsive", options = list(iDisplayLength = 5), diff --git a/R/waffle_continent.R b/R/waffle_continent.R index fb95cae..63a8384 100644 --- a/R/waffle_continent.R +++ b/R/waffle_continent.R @@ -26,6 +26,7 @@ #' @export waffle_continent <- function(data) { + insight::check_if_installed(c("waffle", "ggplot2")) x <- data %>% dplyr::mutate(missing = sum(is.na(.data$continent)) / dplyr::n()) %>% dplyr::filter(!is.na(.data$continent)) %>% diff --git a/R/waffle_continent_journal.R b/R/waffle_continent_journal.R index 1c86bdd..35d7025 100644 --- a/R/waffle_continent_journal.R +++ b/R/waffle_continent_journal.R @@ -29,6 +29,7 @@ #' @export waffle_continent_journal <- function(data, journal_abbreviation = TRUE) { + insight::check_if_installed(c("waffle", "ggplot2", "RColorBrewer")) if (isTRUE(journal_abbreviation)) { data <- data %>% dplyr::mutate(journal = .data$jabbrv) diff --git a/R/waffle_country.R b/R/waffle_country.R index 8f475ba..0213088 100644 --- a/R/waffle_country.R +++ b/R/waffle_country.R @@ -27,6 +27,7 @@ #' @importFrom ggplot2 layer #' @export waffle_country <- function(data) { + insight::check_if_installed(c("ggflags", "ggplot2", "RColorBrewer")) . <- NULL x <- data %>% dplyr::mutate(missing = sum(is.na(.data$country)) / dplyr::n()) %>% diff --git a/R/waffle_country_journal.R b/R/waffle_country_journal.R index fadd8fc..a5a0cbc 100644 --- a/R/waffle_country_journal.R +++ b/R/waffle_country_journal.R @@ -29,6 +29,7 @@ #' @export waffle_country_journal <- function(data, journal_abbreviation = TRUE) { + insight::check_if_installed(c("waffle", "ggplot2", "RColorBrewer")) . <- NULL if (isTRUE(journal_abbreviation)) { data <- data %>%