diff --git a/R/PRISMA_flowdiagram.R b/R/PRISMA_flowdiagram.R index a4f891d..6019602 100755 --- a/R/PRISMA_flowdiagram.R +++ b/R/PRISMA_flowdiagram.R @@ -240,7 +240,7 @@ PRISMA_flowdiagram <- function( #nolint paste( paste( "\n", - other_excluded[, 1], + PRISMA_escape_text_(other_excluded[, 1]), " (n = ", other_excluded[, 2], ")", sep = "" ), @@ -375,7 +375,7 @@ PRISMA_flowdiagram <- function( #nolint paste( paste( "\n", - dbr_excluded[, 1], + PRISMA_escape_text_(dbr_excluded[, 1]), " (n = ", dbr_excluded[, 2], ")", sep = "" ), @@ -1447,7 +1447,7 @@ PRISMA_data <- function(data) { #nolint ) dbr_excluded <- data.frame( reason = gsub( - ",.*$", + ",\\s*\\d+\\s*$", "", unlist( strsplit( @@ -1464,8 +1464,8 @@ PRISMA_data <- function(data) { #nolint ) ), n = gsub( - ".*,", - "", + "^.*,\\s*(\\d+)\\s*$", + "\\1", unlist( strsplit( as.character( @@ -1493,7 +1493,7 @@ PRISMA_data <- function(data) { #nolint ) other_excluded <- data.frame( reason = gsub( - ",.*$", + ",\\s*\\d+\\s*$", "", unlist( strsplit( @@ -1510,8 +1510,8 @@ PRISMA_data <- function(data) { #nolint ) ), n = gsub( - ".*,", - "", + "^.*,\\s*(\\d+)\\s*$", + "\\1", unlist( strsplit( as.character( diff --git a/R/utils.R b/R/utils.R index b7fa688..2a0ff59 100644 --- a/R/utils.R +++ b/R/utils.R @@ -1,5 +1,17 @@ # Utility functions for PRISMA_flowdiagram +#' Escape special characters for DOT syntax +#' @keywords internal +PRISMA_escape_text_ <- function(text) { #nolint + if (is.null(text)) return(text) + text <- as.character(text) + # Escape backslashes first, then quotes and apostrophes + text <- gsub("\\", "\\\\", text, fixed = TRUE) + text <- gsub('"', '\\"', text, fixed = TRUE) + text <- gsub("'", "\\'", text, fixed = TRUE) + return(text) +} + #' Calculate the correct height of a box from a list (e.g. of exclusion reasons) #' @description Get the correct height for a box #' @param n the number of rows of text in the label