diff --git a/DESCRIPTION b/DESCRIPTION index 818da35..2b32215 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: PRISMA2020 Title: Make Interactive 'PRISMA' Flow Diagrams -Version: 1.1.2 +Version: 1.1.3 Authors@R: c( person(given = "Neal", family = "Haddaway", @@ -14,7 +14,10 @@ Authors@R: c( email = "chris.pritchard@ntu.ac.uk", comment = c(ORCID = "0000-0002-1143-9751")), person("Brennan", "Chapman", role = "ctb"), - person("Hossam", "Hammady", role= "ctb")) + person("Hossam", "Hammady", role = "ctb"), + person("Anders", "Kolstad", role = "ctb", comment = c(ORCID = "0000-0002-9623-9491")), + person("Shreya", "Dimri", role = "ctb", comment = c(ORCID = "0009-0009-2155-7506")), + person("Matt Lloyd", "Jones", role = "ctb", comment = c(ORCID = "0000-0001-5841-4554"))) Description: Systematic reviews should be described in a high degree of methodological detail. The 'PRISMA' Statement calls for a high level of reporting detail in systematic reviews and meta-analyses. An integral part @@ -31,11 +34,14 @@ Imports: cpp11, DiagrammeR, DiagrammeRsvg, + dplyr, htmltools, htmlwidgets, progress, + rmarkdown, rsvg, scales, + sessioninfo, shiny, shinyjs, stats, diff --git a/R/PRISMA_data.R b/R/PRISMA_data.R new file mode 100644 index 0000000..925f3ec --- /dev/null +++ b/R/PRISMA_data.R @@ -0,0 +1,428 @@ +#' Read in PRISMA flow diagram data +#' +#' @description Read in a template CSV containing data for the flow diagram +#' @param data File to read in. +#' @return A list of objects needed to plot the flow diagram +#' @examples +#' csvFile <- system.file("extdata", "PRISMA.csv", package = "PRISMA2020") +#' data <- read.csv(csvFile); +#' data <- PRISMA_data(data); +#' @export +PRISMA_data <- function(data) { #nolint + # Ensure data is a df, not a tibble; + # tibbles do not return vectors using df[, 1]. + data <- as.data.frame(data) + #Set parameters + previous_studies <- scales::comma( + PRISMA_format_number_( #nolint + data[ + grep( + "previous_studies", + data[, 1] + ), + ]$n + ) + ) + previous_reports <- scales::comma( + PRISMA_format_number_( #nolint + data[ + grep( + "previous_reports", + data[, 1] + ), + ]$n + ) + ) + register_results <- scales::comma( + PRISMA_format_number_( #nolint + data[ + grep( + "register_results", + data[, 1] + ), + ]$n + ) + ) + database_results <- scales::comma( + PRISMA_format_number_( #nolint + data[ + grep( + "database_results", + data[, 1] + ), + ]$n + ) + ) + database_specific_results <- PRISMA_parse_reasons_(data[ #nolint + grep( + "database_specific_results", + data[, 1] + ), + ]$n + ) + register_specific_results <- PRISMA_parse_reasons_(data[ #nolint + grep( + "register_specific_results", + data[, 1] + ), + ]$n + ) + website_results <- scales::comma( + PRISMA_format_number_( #nolint + data[ + grep( + "website_results", + data[, 1] + ), + ]$n + ) + ) + organisation_results <- scales::comma( + PRISMA_format_number_( #nolint + data[ + grep( + "organisation_results", + data[, 1] + ), + ]$n + ) + ) + citations_results <- scales::comma( + PRISMA_format_number_( #nolint + data[ + grep( + "citations_results", + data[, 1] + ), + ]$n + ) + ) + duplicates <- scales::comma( + PRISMA_format_number_( #nolint + data[ + grep( + "duplicates", + data[, 1] + ), + ]$n + ) + ) + excluded_automatic <- scales::comma( + PRISMA_format_number_( #nolint + data[ + grep( + "excluded_automatic", + data[, 1] + ), + ]$n + ) + ) + excluded_other <- scales::comma( + PRISMA_format_number_( #nolint + data[ + grep( + "excluded_other", + data[, 1] + ), + ]$n + ) + ) + records_screened <- scales::comma( + PRISMA_format_number_( #nolint + data[ + grep( + "records_screened", + data[, 1] + ), + ]$n + ) + ) + records_excluded <- scales::comma( + PRISMA_format_number_( #nolint + data[ + grep( + "records_excluded", + data[, 1] + ), + ]$n + ) + ) + dbr_sought_reports <- scales::comma( + PRISMA_format_number_( #nolint + data[ + grep( + "dbr_sought_reports", + data[, 1] + ), + ]$n + ) + ) + dbr_notretrieved_reports <- scales::comma( + PRISMA_format_number_( #nolint + data[ + grep( + "dbr_notretrieved_reports", + data[, 1] + ), + ]$n + ) + ) + other_sought_reports <- scales::comma( + PRISMA_format_number_( #nolint + data[ + grep( + "other_sought_reports", + data[, 1] + ), + ]$n + ) + ) + other_notretrieved_reports <- scales::comma( + PRISMA_format_number_( #nolint + data[ + grep( + "other_notretrieved_reports", + data[, 1] + ), + ]$n + ) + ) + dbr_assessed <- scales::comma( + PRISMA_format_number_( #nolint + data[ + grep( + "dbr_assessed", + data[, 1] + ), + ]$n + ) + ) + dbr_excluded <- PRISMA_parse_reasons_(data[ #nolint + grep( + "dbr_excluded", + data[, 1] + ), + ]$n + ) + other_assessed <- scales::comma( + PRISMA_format_number_( #nolint + data[ + grep( + "other_assessed", + data[, 1] + ), + ]$n + ) + ) + other_excluded <- PRISMA_parse_reasons_(data[ #nolint + grep( + "other_excluded", + data[, 1] + ), + ]$n + ) + new_studies <- scales::comma( + PRISMA_format_number_( #nolint + data[ + grep( + "new_studies", + data[, 1] + ), + ]$n + ) + ) + new_reports <- scales::comma( + PRISMA_format_number_( #nolint + data[ + grep( + "new_reports", + data[, 1] + ), + ]$n + ) + ) + total_studies <- scales::comma( + PRISMA_format_number_( #nolint + data[ + grep( + "total_studies$", + data[, 1] + ), + ]$n + ) + ) + total_reports <- scales::comma( + PRISMA_format_number_( #nolint + data[ + grep( + "total_reports$", + data[, 1] + ), + ]$n + ) + ) + total_studies_ma <- scales::comma( + PRISMA_format_number_( #nolint + data[ + grep( + "total_studies_ma", + data[, 1] + ), + ]$n + ) + ) + total_reports_ma <- scales::comma( + PRISMA_format_number_( #nolint + data[ + grep( + "total_reports_ma", + data[, 1] + ), + ]$n + ) + ) + tooltips <- list() + for (i in seq_len(nrow(data))) { + if (!is.na(data[i, ]$tooltips)) { + if (is.na(data[i, ]$data)) { + name <- data[i, ]$box + } else { + name <- data[i, ]$data + } + tooltips[[name]] <- data[i, ]$tooltips + } + } + + urls <- data.frame( + box = data[!duplicated(data$box), ]$box, + url = data[!duplicated(data$box), ]$url + ) + #set text - if text >33 characters, + previous_text <- data[grep("prevstud", data[, 3]), ]$boxtext + newstud_text <- data[grep("newstud", data[, 3]), ]$boxtext + other_text <- data[grep("othstud", data[, 3]), ]$boxtext + previous_studies_text <- data[grep("previous_studies", data[, 1]), ]$boxtext + previous_reports_text <- data[grep("previous_reports", data[, 1]), ]$boxtext + register_results_text <- data[grep("register_results", data[, 1]), ]$boxtext + database_results_text <- data[grep("database_results", data[, 1]), ]$boxtext + website_results_text <- data[grep("website_results", data[, 1]), ]$boxtext + organisation_results_text <- data[ + grep( + "organisation_results", + data[, 1] + ), + ]$boxtext + citations_results_text <- data[grep("citations_results", data[, 1]), ]$boxtext + duplicates_text <- data[grep("duplicates", data[, 1]), ]$boxtext + excluded_automatic_text <- data[ + grep( + "excluded_automatic", + data[, 1] + ), + ]$boxtext + excluded_other_text <- data[grep("excluded_other", data[, 1]), ]$boxtext + records_screened_text <- data[grep("records_screened", data[, 1]), ]$boxtext + records_excluded_text <- data[grep("records_excluded", data[, 1]), ]$boxtext + dbr_sought_reports_text <- data[ + grep( + "dbr_sought_reports", + data[, 1] + ), + ]$boxtext + dbr_notretrieved_reports_text <- data[ + grep( + "dbr_notretrieved_reports", + data[, 1] + ), + ]$boxtext + other_sought_reports_text <- data[ + grep( + "other_sought_reports", + data[, 1] + ), + ]$boxtext + other_notretrieved_reports_text <- data[ #nolint + grep( + "other_notretrieved_reports", + data[, 1] + ), + ]$boxtext + dbr_assessed_text <- data[grep("dbr_assessed", data[, 1]), ]$boxtext + dbr_excluded_text <- data[grep("dbr_excluded", data[, 1]), ]$boxtext + other_assessed_text <- data[grep("other_assessed", data[, 1]), ]$boxtext + other_excluded_text <- data[grep("other_excluded", data[, 1]), ]$boxtext + new_studies_text <- data[grep("new_studies", data[, 1]), ]$boxtext + new_reports_text <- data[grep("new_reports", data[, 1]), ]$boxtext + total_studies_text <- data[grep("total_studies$", data[, 1]), ]$boxtext + total_reports_text <- data[grep("total_reports$", data[, 1]), ]$boxtext + identification_text <- data[grep("identification", data[, 1]), ]$boxtext + screening_text <- data[grep("screening", data[, 1]), ]$boxtext + included_text <- data[grep("included", data[, 1]), ]$boxtext + total_studies_ma_text <- data[grep("total_studies_ma", data[, 1]), ]$boxtext + total_reports_ma_text <- data[grep("total_reports_ma", data[, 1]), ]$boxtext + x <- list( + previous_studies = previous_studies, + previous_reports = previous_reports, + register_results = register_results, + database_results = database_results, + database_specific_results = database_specific_results, + register_specific_results = register_specific_results, + website_results = website_results, + organisation_results = organisation_results, + citations_results = citations_results, + duplicates = duplicates, + excluded_automatic = excluded_automatic, + excluded_other = excluded_other, + records_screened = records_screened, + records_excluded = records_excluded, + dbr_sought_reports = dbr_sought_reports, + dbr_notretrieved_reports = dbr_notretrieved_reports, + other_sought_reports = other_sought_reports, + other_notretrieved_reports = other_notretrieved_reports, + dbr_assessed = dbr_assessed, + dbr_excluded = dbr_excluded, + other_assessed = other_assessed, + other_excluded = other_excluded, + new_studies = new_studies, + new_reports = new_reports, + total_studies = total_studies, + total_reports = total_reports, + total_studies_ma = total_studies_ma, + total_reports_ma = total_reports_ma, + previous_text = previous_text, + newstud_text = newstud_text, + other_text = other_text, + previous_studies_text = previous_studies_text, + previous_reports_text = previous_reports_text, + register_results_text = register_results_text, + database_results_text = database_results_text, + website_results_text = website_results_text, + organisation_results_text = organisation_results_text, + citations_results_text = citations_results_text, + duplicates_text = duplicates_text, + excluded_automatic_text = excluded_automatic_text, + excluded_other_text = excluded_other_text, + records_screened_text = records_screened_text, + records_excluded_text = records_excluded_text, + dbr_sought_reports_text = dbr_sought_reports_text, + dbr_notretrieved_reports_text = dbr_notretrieved_reports_text, + other_sought_reports_text = other_sought_reports_text, + other_notretrieved_reports_text = other_notretrieved_reports_text, + dbr_assessed_text = dbr_assessed_text, + dbr_excluded_text = dbr_excluded_text, + other_assessed_text = other_assessed_text, + other_excluded_text = other_excluded_text, + new_studies_text = new_studies_text, + new_reports_text = new_reports_text, + total_studies_text = total_studies_text, + total_reports_text = total_reports_text, + total_studies_ma_text = total_studies_ma_text, + total_reports_ma_text = total_reports_ma_text, + identification_text = identification_text, + screening_text = screening_text, + included_text = included_text, + tooltips = tooltips, + urls = urls + ) + return(x) +} diff --git a/R/PRISMA_flowdiagram.R b/R/PRISMA_flowdiagram.R index 152fc43..a0393f5 100755 --- a/R/PRISMA_flowdiagram.R +++ b/R/PRISMA_flowdiagram.R @@ -1,12 +1,3 @@ -# Suppress R CMD check note -#' @importFrom DT addRow -#' @importFrom rio import -#' @importFrom shiny column -#' @importFrom shinyjs alert -#' @importFrom stats median -#' @importFrom utils apropos -#' @importFrom webp read_webp -NULL #' Plot interactive flow diagrams for systematic reviews #' @description Produces a PRISMA2020 style flow diagram #' for systematic reviews, with the option to add @@ -1238,820 +1229,3 @@ PRISMA_flowdiagram <- function( #nolint } return(x) } - - -#' Read in PRISMA flow diagram data -#' -#' @description Read in a template CSV containing data for the flow diagram -#' @param data File to read in. -#' @return A list of objects needed to plot the flow diagram -#' @examples -#' csvFile <- system.file("extdata", "PRISMA.csv", package = "PRISMA2020") -#' data <- read.csv(csvFile); -#' data <- PRISMA_data(data); -#' @export -PRISMA_data <- function(data) { #nolint - # Ensure data is a df, not a tibble; - # tibbles do not return vectors using df[, 1]. - data <- as.data.frame(data) - #Set parameters - previous_studies <- scales::comma( - PRISMA_format_number_( - PRISMA_default_or_csv_( - expr = data[ - grep( - "previous_studies", - data[, 1] - ), - ]$n, - default = 0, - var_name = "previous_studies" - ) - ) - ) - previous_reports <- scales::comma( - PRISMA_format_number_( - PRISMA_default_or_csv_( - expr = data[ - grep( - "previous_reports", - data[, 1] - ), - ]$n, - default = 0, - var_name = "previous_reports" - ) - ) - ) - register_results <- scales::comma( - PRISMA_format_number_( #nolint - PRISMA_default_or_csv_( - expr = data[ - grep( - "register_results", - data[, 1] - ), - ]$n, - default = 0, - var_name = "register_results" - ) - ) - ) - database_results <- scales::comma( - PRISMA_format_number_( #nolint - PRISMA_default_or_csv_( - expr = data[ - grep( - "database_results", - data[, 1] - ), - ]$n, - default = 0, - var_name = "database_results" - ) - ) - ) - database_specific_results <- PRISMA_parse_reasons_( - PRISMA_default_or_csv_( - expr = data[ #nolint - grep( - "database_specific_results", - data[, 1] - ), - ]$n, - default = "Database 1, xxx; Database 2, xxx; Database 3, xxx", - var_name = "database_specific_results" - ) - ) - register_specific_results <- PRISMA_parse_reasons_( - PRISMA_default_or_csv_( - expr = data[ #nolint - grep( - "register_specific_results", - data[, 1] - ), - ]$n, - default = "Register 1, xxx; Register 2, xxx; Register 3, xxx", - var_name = "register_specific_results" - ) - ) - website_results <- scales::comma( - PRISMA_format_number_( #nolint - PRISMA_default_or_csv_( - expr = data[ - grep( - "website_results", - data[, 1] - ), - ]$n, - default = 0, - var_name = "website_results" - ) - ) - ) - organisation_results <- scales::comma( - PRISMA_format_number_( #nolint - PRISMA_default_or_csv_( - expr = data[ - grep( - "organisation_results", - data[, 1] - ), - ]$n, - default = 0, - var_name = "organisation_results" - ) - ) - ) - citations_results <- scales::comma( - PRISMA_format_number_( #nolint - PRISMA_default_or_csv_( - expr = data[ - grep( - "citations_results", - data[, 1] - ), - ]$n, - default = 0, - var_name = "citations_results" - ) - ) - ) - duplicates <- scales::comma( - PRISMA_format_number_( #nolint - PRISMA_default_or_csv_( - expr = data[ - grep( - "duplicates", - data[, 1] - ), - ]$n, - default = 0, - var_name = "duplicates" - ) - ) - ) - excluded_automatic <- scales::comma( - PRISMA_format_number_( #nolint - PRISMA_default_or_csv_( - expr = data[ - grep( - "excluded_automatic", - data[, 1] - ), - ]$n, - default = 0, - var_name = "excluded_automatic" - ) - ) - ) - excluded_other <- scales::comma( - PRISMA_format_number_( #nolint - PRISMA_default_or_csv_( - expr = data[ - grep( - "excluded_other", - data[, 1] - ), - ]$n, - default = 0, - var_name = "excluded_other" - ) - ) - ) - records_screened <- scales::comma( - PRISMA_format_number_( #nolint - PRISMA_default_or_csv_( - expr = data[ - grep( - "records_screened", - data[, 1] - ), - ]$n, - default = 0, - var_name = "records_screened" - ) - ) - ) - records_excluded <- scales::comma( - PRISMA_format_number_( #nolint - PRISMA_default_or_csv_( - expr = data[ - grep( - "records_excluded", - data[, 1] - ), - ]$n, - default = 0, - var_name = "records_excluded" - ) - ) - ) - dbr_sought_reports <- scales::comma( - PRISMA_format_number_( #nolint - PRISMA_default_or_csv_( - expr = data[ - grep( - "dbr_sought_reports", - data[, 1] - ), - ]$n, - default = 0, - var_name = "dbr_sought_reports" - ) - ) - ) - dbr_notretrieved_reports <- scales::comma( - PRISMA_format_number_( #nolint - PRISMA_default_or_csv_( - expr = data[ - grep( - "dbr_notretrieved_reports", - data[, 1] - ), - ]$n, - default = 0, - var_name = "dbr_notretrieved_reports" - ) - ) - ) - other_sought_reports <- scales::comma( - PRISMA_format_number_( #nolint - PRISMA_default_or_csv_( - expr = data[ - grep( - "other_sought_reports", - data[, 1] - ), - ]$n, - default = 0, - var_name = "other_sought_reports" - ) - ) - ) - other_notretrieved_reports <- scales::comma( - PRISMA_format_number_( #nolint - PRISMA_default_or_csv_( - expr = data[ - grep( - "other_notretrieved_reports", - data[, 1] - ), - ]$n, - default = 0, - var_name = "other_notretrieved_reports" - ) - ) - ) - dbr_assessed <- scales::comma( - PRISMA_format_number_( #nolint - PRISMA_default_or_csv_( - expr = data[ - grep( - "dbr_assessed", - data[, 1] - ), - ]$n, - default = 0, - var_name = "dbr_assessed" - ) - ) - ) - dbr_excluded <- PRISMA_parse_reasons_( - PRISMA_default_or_csv_( - expr = data[ #nolint - grep( - "dbr_excluded", - data[, 1] - ), - ]$n, - default = "Reason1, xxx; Reason2, xxx; Reason3, xxx", - var_name = "dbr_excluded" - ) - ) - other_assessed <- scales::comma( - PRISMA_format_number_( #nolint - PRISMA_default_or_csv_( - expr = data[ - grep( - "other_assessed", - data[, 1] - ), - ]$n, - default = 0, - var_name = "other_assessed" - ) - ) - ) - other_excluded <- PRISMA_parse_reasons_( - PRISMA_default_or_csv_( - expr = data[ #nolint - grep( - "other_excluded", - data[, 1] - ), - ]$n, - default = "Reason1, xxx; Reason2, xxx; Reason3, xxx", - var_name = "other_excluded" - ) - ) - new_studies <- scales::comma( - PRISMA_format_number_( #nolint - PRISMA_default_or_csv_( - expr = data[ - grep( - "new_studies", - data[, 1] - ), - ]$n, - default = 0, - var_name = "new_studies" - ) - ) - ) - new_reports <- scales::comma( - PRISMA_format_number_( #nolint - PRISMA_default_or_csv_( - expr = data[ - grep( - "new_reports", - data[, 1] - ), - ]$n, - default = 0, - var_name = "new_reports" - ) - ) - ) - total_studies <- scales::comma( - PRISMA_format_number_( #nolint - PRISMA_default_or_csv_( - expr = data[ - grep( - "total_studies$", - data[, 1] - ), - ]$n, - default = 0, - var_name = "total_studies$" - ) - ) - ) - total_reports <- scales::comma( - PRISMA_format_number_( #nolint - PRISMA_default_or_csv_( - expr = data[ - grep( - "total_reports$", - data[, 1] - ), - ]$n, - default = 0, - var_name = "total_reports$" - ) - ) - ) - total_studies_ma <- scales::comma( - PRISMA_format_number_( #nolint - PRISMA_default_or_csv_( - expr = data[ - grep( - "total_studies_ma", - data[, 1] - ), - ]$n, - default = 0, - var_name = "total_studies_ma" - ) - ) - ) - total_reports_ma <- scales::comma( - PRISMA_format_number_( #nolint - PRISMA_default_or_csv_( - expr = data[ - grep( - "total_reports_ma", - data[, 1] - ), - ]$n, - default = 0, - var_name = "total_reports_ma" - ) - ) - ) - tooltips <- list() - for (i in seq_len(nrow(data))) { - if (!is.na(data[i, ]$tooltips)) { - if (is.na(data[i, ]$data)) { - name <- data[i, ]$box - } else { - name <- data[i, ]$data - } - tooltips[[name]] <- data[i, ]$tooltips - } - } - - urls <- data.frame( - box = data[!duplicated(data$box), ]$box, - url = data[!duplicated(data$box), ]$url - ) - #set text - if text >33 characters, - previous_text <- PRISMA_default_or_csv_( - expr = data[grep("prevstud", data[, 3]), ]$boxtext, - default = "Previous studies", - var_name = previous_text - ) - newstud_text <- PRISMA_default_or_csv_( - expr = data[grep("newstud", data[, 3]), ]$boxtext, - default = "Identification of new studies via databases and registers", - var_name = newstud_text - ) - other_text <- PRISMA_default_or_csv_( - expr = data[grep("othstud", data[, 3]), ]$boxtext, - default = "Identification of new studies via other methods", - var_name = other_text - ) - previous_studies_text <- PRISMA_default_or_csv_( - expr = data[grep("previous_studies", data[, 1]), ]$boxtext, - default = "Studies included in previous version of review", - var_name = previous_studies_text - ) - previous_reports_text <- PRISMA_default_or_csv_( - expr = data[grep("previous_reports", data[, 1]), ]$boxtext, - default = "Reports of studies included in previous version of review", - var_name = previous_reports_text - ) - register_results_text <- PRISMA_default_or_csv_( - expr = data[grep("register_results", data[, 1]), ]$boxtext, - default = "Registers", - var_name = register_results_text - ) - database_results_text <- PRISMA_default_or_csv_( - expr = data[grep("database_results", data[, 1]), ]$boxtext, - default = "Databases", - var_name = database_results_text - ) - website_results_text <- PRISMA_default_or_csv_( - expr = data[grep("website_results", data[, 1]), ]$boxtext, - default = "Websites", - var_name = website_results_text - ) - organisation_results_text <- PRISMA_default_or_csv_( - expr = data[grep("organisation_results", data[, 1]),]$boxtext, - default = "Organisations", - var_name = organisation_results_text - ) - citations_results_text <- PRISMA_default_or_csv_( - expr = data[grep("citations_results", data[, 1]), ]$boxtext, - default = "Citation searching", - var_name = citations_results_text - ) - duplicates_text <- PRISMA_default_or_csv_( - expr = data[grep("duplicates", data[, 1]), ]$boxtext, - default = "Duplicate records", - var_name = duplicates_text - ) - excluded_automatic_text <- PRISMA_default_or_csv_( - expr = data[grep("excluded_automatic", data[, 1]),]$boxtext, - default = "Records marked as ineligible by automation tools", - var_name = excluded_automatic_text - ) - excluded_other_text <- PRISMA_default_or_csv_( - expr = data[grep("excluded_other", data[, 1]), ]$boxtext, - default = "Records removed for other reasons", - var_name = excluded_other_text - ) - records_screened_text <- PRISMA_default_or_csv_( - expr = data[grep("records_screened", data[, 1]), ]$boxtext, - default = "Records screened", - var_name = records_screened_text - ) - records_excluded_text <- PRISMA_default_or_csv_( - expr = data[grep("records_excluded", data[, 1]), ]$boxtext, - default = "Records excluded", - var_name = records_excluded_text - ) - dbr_sought_reports_text <- PRISMA_default_or_csv_( - expr = data[grep("dbr_sought_reports", data[, 1]),]$boxtext, - default = "Reports sought for retrieval", - var_name = dbr_sought_reports_text - ) - dbr_notretrieved_reports_text <- PRISMA_default_or_csv_( - expr = data[grep("dbr_notretrieved_reports", data[, 1]),]$boxtext, - default = "Reports not retrieved", - var_name = dbr_notretrieved_reports_text - ) - other_sought_reports_text <- PRISMA_default_or_csv_( - expr = data[ grep("other_sought_reports", data[, 1]),]$boxtext, - default = "Reports sought for retrieval", - var_name = other_sought_reports_text - ) - other_notretrieved_reports_text <- PRISMA_default_or_csv_( - expr = data[ #nolint - grep("other_notretrieved_reports",data[, 1]),]$boxtext, - default = "Reports not retrieved", - var_name = other_notretrieved_reports_text - ) - dbr_assessed_text <- PRISMA_default_or_csv_( - expr = data[grep("dbr_assessed", data[, 1]), ]$boxtext, - default = "Reports assessed for eligibility", - var_name = dbr_assessed_text - ) - dbr_excluded_text <- PRISMA_default_or_csv_( - expr = data[grep("dbr_excluded", data[, 1]), ]$boxtext, - default = "Reports excluded", - var_name = dbr_excluded_text - ) - other_assessed_text <- PRISMA_default_or_csv_( - expr = data[grep("other_assessed", data[, 1]), ]$boxtext, - default = "Reports assessed for eligibility", - var_name = other_assessed_text - ) - other_excluded_text <- PRISMA_default_or_csv_( - expr = data[grep("other_excluded", data[, 1]), ]$boxtext, - default = "Reports excluded", - var_name = other_excluded_text - ) - new_studies_text <- PRISMA_default_or_csv_( - expr = data[grep("new_studies", data[, 1]), ]$boxtext, - default = "New studies included in review", - var_name = new_studies_text - ) - new_reports_text <- PRISMA_default_or_csv_( - expr = data[grep("new_reports", data[, 1]), ]$boxtext, - default = "Reports of new included studies", - var_name = new_reports_text - ) - total_studies_text <- PRISMA_default_or_csv_( - expr = data[grep("total_studies$", data[, 1]), ]$boxtext, - default = "Total studies included in review", - var_name = total_studies_text - ) - total_reports_text <- PRISMA_default_or_csv_( - expr = data[grep("total_reports$", data[, 1]), ]$boxtext, - default = "Reports of total included studies", - var_name = total_reports_text - ) - identification_text <- PRISMA_default_or_csv_( - expr = data[grep("identification", data[, 1]), ]$boxtext, - default = "Identification", - var_name = identification_text - ) - screening_text <- PRISMA_default_or_csv_( - expr = data[grep("screening", data[, 1]), ]$boxtext, - default = "Screening", - var_name = screening_text - ) - included_text <- PRISMA_default_or_csv_( - expr = data[grep("included", data[, 1]), ]$boxtext, - default = "Included", - var_name = included_text - ) - total_studies_ma_text <- PRISMA_default_or_csv_( - expr = data[grep("total_studies_ma", data[, 1]), ]$boxtext, - default = "Total studies included in meta-analysis", - var_name = total_studies_ma_text - ) - total_reports_ma_text <- PRISMA_default_or_csv_( - expr = data[grep("total_reports_ma", data[, 1]), ]$boxtext, - default = "Reports of total included studies in meta-analysis", - var_name = total_reports_ma_text - ) - x <- list( - previous_studies = previous_studies, - previous_reports = previous_reports, - register_results = register_results, - database_results = database_results, - database_specific_results = database_specific_results, - register_specific_results = register_specific_results, - website_results = website_results, - organisation_results = organisation_results, - citations_results = citations_results, - duplicates = duplicates, - excluded_automatic = excluded_automatic, - excluded_other = excluded_other, - records_screened = records_screened, - records_excluded = records_excluded, - dbr_sought_reports = dbr_sought_reports, - dbr_notretrieved_reports = dbr_notretrieved_reports, - other_sought_reports = other_sought_reports, - other_notretrieved_reports = other_notretrieved_reports, - dbr_assessed = dbr_assessed, - dbr_excluded = dbr_excluded, - other_assessed = other_assessed, - other_excluded = other_excluded, - new_studies = new_studies, - new_reports = new_reports, - total_studies = total_studies, - total_reports = total_reports, - total_studies_ma = total_studies_ma, - total_reports_ma = total_reports_ma, - previous_text = previous_text, - newstud_text = newstud_text, - other_text = other_text, - previous_studies_text = previous_studies_text, - previous_reports_text = previous_reports_text, - register_results_text = register_results_text, - database_results_text = database_results_text, - website_results_text = website_results_text, - organisation_results_text = organisation_results_text, - citations_results_text = citations_results_text, - duplicates_text = duplicates_text, - excluded_automatic_text = excluded_automatic_text, - excluded_other_text = excluded_other_text, - records_screened_text = records_screened_text, - records_excluded_text = records_excluded_text, - dbr_sought_reports_text = dbr_sought_reports_text, - dbr_notretrieved_reports_text = dbr_notretrieved_reports_text, - other_sought_reports_text = other_sought_reports_text, - other_notretrieved_reports_text = other_notretrieved_reports_text, - dbr_assessed_text = dbr_assessed_text, - dbr_excluded_text = dbr_excluded_text, - other_assessed_text = other_assessed_text, - other_excluded_text = other_excluded_text, - new_studies_text = new_studies_text, - new_reports_text = new_reports_text, - total_studies_text = total_studies_text, - total_reports_text = total_reports_text, - total_studies_ma_text = total_studies_ma_text, - total_reports_ma_text = total_reports_ma_text, - identification_text = identification_text, - screening_text = screening_text, - included_text = included_text, - tooltips = tooltips, - urls = urls - ) - return(x) -} - -#' Save PRISMA2020 flow diagram -#' @description Save the output from [PRISMA_flowdiagram()] to the -#' working directory. -#' @param plotobj A plot produced using [PRISMA_flowdiagram()]. -#' @param filename The filename to save (including extension) -#' @param filetype The filetype to save the plot in, supports: -#' HTML, ZIP, PDF, PNG, SVG, PS and WEBP -#' (if NA, the filetype will be calculated out based on the file extension) -#' HTML files maintain hyperlinks and tooltips -#' The ZIP option creates an archive containing the HTML file, -#' alongside supporting javascript and css files in an adjacent folder, -#' instead of embedded base64 within the HTML file -#' @param overwrite if TRUE, will overwrite an existing file -#' @param width passed as the width argument to -#' [rsvg::rsvg()] and similar functions -#' @param height passed as the height argument to -#' [rsvg::rsvg()] and similar functions -#' @param css passed as the css argument to -#' [rsvg::rsvg()] and similar functions -#' @return the absolute filename of the saved diagram plot. -#' @examples -#' csvFile <- system.file("extdata", "PRISMA.csv", package = "PRISMA2020") -#' data <- read.csv(csvFile); -#' data <- PRISMA_data(data); -#' plot <- PRISMA_flowdiagram(data, -#' fontsize = 12, -#' interactive = TRUE, -#' previous = FALSE, -#' other = TRUE); -#' PRISMA_save(plot, filename = tempfile(), filetype="html"); -#' @export -PRISMA_save <- function( #nolint - plotobj, - filename = "PRISMA2020_flowdiagram.html", - filetype = NA, - overwrite = FALSE, - width = NULL, - height = NULL, - css = NULL -) { - if (!file.exists(filename) || overwrite == TRUE) { - format_real <- PRISMA_calc_filetype_(filename, filetype) #nolint - switch( - format_real, - "HTML" = { - tmp_html <- tempfile( - pattern = "PRISMA2020_", - tmpdir = tempdir(), - fileext = ".html" - ) - htmlwidgets::saveWidget( - plotobj, - file = tmp_html, - title = "PRISMA2020 Flowdiagram" - ) - if (!(file.copy(tmp_html, filename, overwrite = TRUE))) { - stop("Error saving HTML") - } - file.remove(tmp_html) - }, - "ZIP" = { - curr_wd <- getwd() - tmp_dir <- tempdir() - setwd(tmp_dir) - tmp_zipfile <- tempfile( - pattern = "PRISMA2020_", - tmpdir = tempdir(), - fileext = ".zip" - ) - tmp_html <- paste0( - tools::file_path_sans_ext(basename(filename)), - ".html" - ) - tmp_libdir <- paste0(tmp_html, "_files") - htmlwidgets::saveWidget( - plotobj, - file = tmp_html, - libdir = tmp_libdir, - selfcontained = FALSE, - title = "PRISMA2020 Flowdiagram" - ) - zip::zip(zipfile = tmp_zipfile, files = c(tmp_html, tmp_libdir)) - setwd(curr_wd) - if (!(file.copy(paste0(tmp_zipfile), filename, overwrite = TRUE))) { - stop("Error saving ZIP File") - } - }, - "PDF" = { - tmp_svg <- PRISMA_gen_tmp_svg_(plotobj) #nolint - rsvg::rsvg_pdf( - tmp_svg, - filename, - width = width, - height = height, - css = css - ) - file.remove(tmp_svg) - }, - "PNG" = { - tmp_svg <- PRISMA_gen_tmp_svg_(plotobj) #nolint - rsvg::rsvg_png( - tmp_svg, - filename, - width = width, - height = height, - css = css - ) - file.remove(tmp_svg) - }, - "SVG" = { - tmp_svg <- PRISMA_gen_tmp_svg_(plotobj) #nolint - if (!(file.copy(tmp_svg, filename, overwrite = TRUE))) { - stop("Error saving SVG") - } - file.remove(tmp_svg) - }, - "PS" = { - tmp_svg <- PRISMA_gen_tmp_svg_(plotobj) #nolint - rsvg::rsvg_ps( - tmp_svg, - filename, - width = width, - height = height, - css = css - ) - file.remove(tmp_svg) - }, - "WEBP" = { - tmp_svg <- PRISMA_gen_tmp_svg_(plotobj) #nolint - rsvg::rsvg_webp( - tmp_svg, - filename, - width = width, - height = height, - css = css - ) - file.remove(tmp_svg) - }, - stop("Please choose one of the supported file types") - ) - return(tools::file_path_as_absolute(filename)) - } else { - stop("File exists, please set overwite = TRUE to overwrite") - } -} - -#' Defunct function - replaced by "PRISMA_interactive_" -#' @description Defunct function - replaced by "PRISMA_interactive_" -#' @seealso [PRISMA_interactive_()] -#' @param plot A plot object from [PRISMA_flowdiagram()]. -#' @param urls A dataframe consisting of two columns: nodes and urls. The first -#' column should contain 19 rows for the nodes from node1 to node19. The second -#' column should contain a corresponding URL for each node. -#' @param previous Logical argument (TRUE or FALSE) (supplied through -#' [PRISMA_flowdiagram()]) specifying whether previous studies were sought. -#' @param other Logical argument (TRUE or FALSE) (supplied through -#' [PRISMA_flowdiagram()]) specifying whether other studies were sought. -sr_flow_interactive <- function(plot, - urls, - previous, - other) { - .Defunct("PRISMA_interactive_") -} - -#' Defunct function - replaced by "PRISMA_data" -#' @description Defunct function - replaced by "PRISMA_data" -#' @seealso [PRISMA_data()] -#' @param data File to read in. -read_PRISMAdata <- function(data){ #nolint - .Defunct("PRISMA_data") -} diff --git a/R/PRISMA_save.R b/R/PRISMA_save.R new file mode 100644 index 0000000..0f8919b --- /dev/null +++ b/R/PRISMA_save.R @@ -0,0 +1,145 @@ +#' Save PRISMA2020 flow diagram +#' @description Save the output from [PRISMA_flowdiagram()] to the +#' working directory. +#' @param plotobj A plot produced using [PRISMA_flowdiagram()]. +#' @param filename The filename to save (including extension) +#' @param filetype The filetype to save the plot in, supports: +#' HTML, ZIP, PDF, PNG, SVG, PS and WEBP +#' (if NA, the filetype will be calculated out based on the file extension) +#' HTML files maintain hyperlinks and tooltips +#' The ZIP option creates an archive containing the HTML file, +#' alongside supporting javascript and css files in an adjacent folder, +#' instead of embedded base64 within the HTML file +#' @param overwrite if TRUE, will overwrite an existing file +#' @param width passed as the width argument to +#' [rsvg::rsvg()] and similar functions +#' @param height passed as the height argument to +#' [rsvg::rsvg()] and similar functions +#' @param css passed as the css argument to +#' [rsvg::rsvg()] and similar functions +#' @return the absolute filename of the saved diagram plot. +#' @examples +#' csvFile <- system.file("extdata", "PRISMA.csv", package = "PRISMA2020") +#' data <- read.csv(csvFile); +#' data <- PRISMA_data(data); +#' plot <- PRISMA_flowdiagram(data, +#' fontsize = 12, +#' interactive = TRUE, +#' previous = FALSE, +#' other = TRUE); +#' PRISMA_save(plot, filename = tempfile(), filetype="html"); +#' @export +PRISMA_save <- function( #nolint + plotobj, + filename = "PRISMA2020_flowdiagram.html", + filetype = NA, + overwrite = FALSE, + width = NULL, + height = NULL, + css = NULL +) { + if (!file.exists(filename) || overwrite == TRUE) { + format_real <- PRISMA_calc_filetype_(filename, filetype) #nolint + switch( + format_real, + "HTML" = { + tmp_html <- tempfile( + pattern = "PRISMA2020_", + tmpdir = tempdir(), + fileext = ".html" + ) + htmlwidgets::saveWidget( + plotobj, + file = tmp_html, + title = "PRISMA2020 Flowdiagram" + ) + if (!(file.copy(tmp_html, filename, overwrite = TRUE))) { + stop("Error saving HTML") + } + file.remove(tmp_html) + }, + "ZIP" = { + curr_wd <- getwd() + tmp_dir <- tempdir() + setwd(tmp_dir) + tmp_zipfile <- tempfile( + pattern = "PRISMA2020_", + tmpdir = tempdir(), + fileext = ".zip" + ) + tmp_html <- paste0( + tools::file_path_sans_ext(basename(filename)), + ".html" + ) + tmp_libdir <- paste0(tmp_html, "_files") + htmlwidgets::saveWidget( + plotobj, + file = tmp_html, + libdir = tmp_libdir, + selfcontained = FALSE, + title = "PRISMA2020 Flowdiagram" + ) + zip::zip(zipfile = tmp_zipfile, files = c(tmp_html, tmp_libdir)) + setwd(curr_wd) + if (!(file.copy(paste0(tmp_zipfile), filename, overwrite = TRUE))) { + stop("Error saving ZIP File") + } + }, + "PDF" = { + tmp_svg <- PRISMA_gen_tmp_svg_(plotobj) #nolint + rsvg::rsvg_pdf( + tmp_svg, + filename, + width = width, + height = height, + css = css + ) + file.remove(tmp_svg) + }, + "PNG" = { + tmp_svg <- PRISMA_gen_tmp_svg_(plotobj) #nolint + rsvg::rsvg_png( + tmp_svg, + filename, + width = width, + height = height, + css = css + ) + file.remove(tmp_svg) + }, + "SVG" = { + tmp_svg <- PRISMA_gen_tmp_svg_(plotobj) #nolint + if (!(file.copy(tmp_svg, filename, overwrite = TRUE))) { + stop("Error saving SVG") + } + file.remove(tmp_svg) + }, + "PS" = { + tmp_svg <- PRISMA_gen_tmp_svg_(plotobj) #nolint + rsvg::rsvg_ps( + tmp_svg, + filename, + width = width, + height = height, + css = css + ) + file.remove(tmp_svg) + }, + "WEBP" = { + tmp_svg <- PRISMA_gen_tmp_svg_(plotobj) #nolint + rsvg::rsvg_webp( + tmp_svg, + filename, + width = width, + height = height, + css = css + ) + file.remove(tmp_svg) + }, + stop("Please choose one of the supported file types") + ) + return(tools::file_path_as_absolute(filename)) + } else { + stop("File exists, please set overwite = TRUE to overwrite") + } +} diff --git a/R/defunct.R b/R/defunct.R new file mode 100644 index 0000000..45332ff --- /dev/null +++ b/R/defunct.R @@ -0,0 +1,25 @@ +#' Defunct function - replaced by "PRISMA_interactive_" +#' @description Defunct function - replaced by "PRISMA_interactive_" +#' @seealso [PRISMA_interactive_()] +#' @param plot A plot object from [PRISMA_flowdiagram()]. +#' @param urls A dataframe consisting of two columns: nodes and urls. The first +#' column should contain 19 rows for the nodes from node1 to node19. The second +#' column should contain a corresponding URL for each node. +#' @param previous Logical argument (TRUE or FALSE) (supplied through +#' [PRISMA_flowdiagram()]) specifying whether previous studies were sought. +#' @param other Logical argument (TRUE or FALSE) (supplied through +#' [PRISMA_flowdiagram()]) specifying whether other studies were sought. +sr_flow_interactive <- function(plot, + urls, + previous, + other) { + .Defunct("PRISMA_interactive_") +} + +#' Defunct function - replaced by "PRISMA_data" +#' @description Defunct function - replaced by "PRISMA_data" +#' @seealso [PRISMA_data()] +#' @param data File to read in. +read_PRISMAdata <- function(data){ #nolint + .Defunct("PRISMA_data") +} diff --git a/R/imports.R b/R/imports.R new file mode 100644 index 0000000..a704ca1 --- /dev/null +++ b/R/imports.R @@ -0,0 +1,9 @@ +# Suppress R CMD check note +#' @importFrom DT addRow +#' @importFrom rio import +#' @importFrom shiny column +#' @importFrom shinyjs alert +#' @importFrom stats median +#' @importFrom utils apropos +#' @importFrom webp read_webp +NULL \ No newline at end of file diff --git a/inst/shiny-examples/PRISMA_flowdiagram/app.R b/inst/shiny-examples/PRISMA_flowdiagram/app.R index 46dbc12..e64ed5a 100644 --- a/inst/shiny-examples/PRISMA_flowdiagram/app.R +++ b/inst/shiny-examples/PRISMA_flowdiagram/app.R @@ -3,7 +3,6 @@ library(shinyjs) library(rsvg) library(DT) #nolint library(rio) -library(devtools) library(PRISMA2020) #nolint template <- read.csv("www/PRISMA.csv", stringsAsFactors = FALSE) #nolint diff --git a/man/PRISMA_data.Rd b/man/PRISMA_data.Rd index a213a3c..b0f7592 100644 --- a/man/PRISMA_data.Rd +++ b/man/PRISMA_data.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/PRISMA_flowdiagram.R +% Please edit documentation in R/PRISMA_data.R \name{PRISMA_data} \alias{PRISMA_data} \title{Read in PRISMA flow diagram data} diff --git a/man/PRISMA_default_or_csv_.Rd b/man/PRISMA_default_or_csv_.Rd new file mode 100644 index 0000000..65a2f6a --- /dev/null +++ b/man/PRISMA_default_or_csv_.Rd @@ -0,0 +1,22 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/utils.R +\name{PRISMA_default_or_csv_} +\alias{PRISMA_default_or_csv_} +\title{Pull from CSV, or use a default value if not in the CSV} +\usage{ +PRISMA_default_or_csv_(expr, default, var_name = "not provided") +} +\arguments{ +\item{expr}{the expression to get the variable from the CSV} + +\item{default}{the default token} + +\item{var_name}{the variable name} +} +\value{ +the result of 'expr', or 'default' +} +\description{ +set the variable from the CSV, or a default value +} +\keyword{internal} diff --git a/man/PRISMA_save.Rd b/man/PRISMA_save.Rd index 1ff1836..57fdde9 100644 --- a/man/PRISMA_save.Rd +++ b/man/PRISMA_save.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/PRISMA_flowdiagram.R +% Please edit documentation in R/PRISMA_save.R \name{PRISMA_save} \alias{PRISMA_save} \title{Save PRISMA2020 flow diagram} diff --git a/man/read_PRISMAdata.Rd b/man/read_PRISMAdata.Rd index 3b52bc8..f7c8ab1 100644 --- a/man/read_PRISMAdata.Rd +++ b/man/read_PRISMAdata.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/PRISMA_flowdiagram.R +% Please edit documentation in R/defunct.R \name{read_PRISMAdata} \alias{read_PRISMAdata} \title{Defunct function - replaced by "PRISMA_data"} diff --git a/man/sr_flow_interactive.Rd b/man/sr_flow_interactive.Rd index 81c2b08..6dceb72 100644 --- a/man/sr_flow_interactive.Rd +++ b/man/sr_flow_interactive.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/PRISMA_flowdiagram.R +% Please edit documentation in R/defunct.R \name{sr_flow_interactive} \alias{sr_flow_interactive} \title{Defunct function - replaced by "PRISMA_interactive_"}