Skip to content

Commit dc3d932

Browse files
authored
Merge pull request #4 from rayyansys/tasks/7797
Handle apostrophes and commas in exclusion reasons
2 parents ffa9126 + 1465adb commit dc3d932

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

R/PRISMA_flowdiagram.R

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ PRISMA_flowdiagram <- function( #nolint
240240
paste(
241241
paste(
242242
"\n",
243-
other_excluded[, 1],
243+
PRISMA_escape_text_(other_excluded[, 1]),
244244
" (n = ", other_excluded[, 2], ")",
245245
sep = ""
246246
),
@@ -375,7 +375,7 @@ PRISMA_flowdiagram <- function( #nolint
375375
paste(
376376
paste(
377377
"\n",
378-
dbr_excluded[, 1],
378+
PRISMA_escape_text_(dbr_excluded[, 1]),
379379
" (n = ", dbr_excluded[, 2], ")",
380380
sep = ""
381381
),
@@ -1447,7 +1447,7 @@ PRISMA_data <- function(data) { #nolint
14471447
)
14481448
dbr_excluded <- data.frame(
14491449
reason = gsub(
1450-
",.*$",
1450+
",\\s*\\d+\\s*$",
14511451
"",
14521452
unlist(
14531453
strsplit(
@@ -1464,8 +1464,8 @@ PRISMA_data <- function(data) { #nolint
14641464
)
14651465
),
14661466
n = gsub(
1467-
".*,",
1468-
"",
1467+
"^.*,\\s*(\\d+)\\s*$",
1468+
"\\1",
14691469
unlist(
14701470
strsplit(
14711471
as.character(
@@ -1493,7 +1493,7 @@ PRISMA_data <- function(data) { #nolint
14931493
)
14941494
other_excluded <- data.frame(
14951495
reason = gsub(
1496-
",.*$",
1496+
",\\s*\\d+\\s*$",
14971497
"",
14981498
unlist(
14991499
strsplit(
@@ -1510,8 +1510,8 @@ PRISMA_data <- function(data) { #nolint
15101510
)
15111511
),
15121512
n = gsub(
1513-
".*,",
1514-
"",
1513+
"^.*,\\s*(\\d+)\\s*$",
1514+
"\\1",
15151515
unlist(
15161516
strsplit(
15171517
as.character(

R/utils.R

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
# Utility functions for PRISMA_flowdiagram
22

3+
#' Escape special characters for DOT syntax
4+
#' @keywords internal
5+
PRISMA_escape_text_ <- function(text) { #nolint
6+
if (is.null(text)) return(text)
7+
text <- as.character(text)
8+
# Escape backslashes first, then quotes and apostrophes
9+
text <- gsub("\\", "\\\\", text, fixed = TRUE)
10+
text <- gsub('"', '\\"', text, fixed = TRUE)
11+
text <- gsub("'", "\\'", text, fixed = TRUE)
12+
return(text)
13+
}
14+
315
#' Calculate the correct height of a box from a list (e.g. of exclusion reasons)
416
#' @description Get the correct height for a box
517
#' @param n the number of rows of text in the label

0 commit comments

Comments
 (0)