@@ -31,6 +31,17 @@ xml_nodes_to_lint <- function(xml, source_file, lint_message,
31
31
))
32
32
}
33
33
34
+ paren_wrap <- function (... , sep ) {
35
+ sep <- paste(" )" , sep , " (" )
36
+ dots <- list (... )
37
+ if (length(dots ) == 1L && length(dots [[1L ]]) > 1L ) {
38
+ inner <- paste(dots [[1L ]], collapse = sep )
39
+ } else {
40
+ inner <- paste(... , sep = sep )
41
+ }
42
+ paste0(" (" , inner , " )" )
43
+ }
44
+
34
45
# ' Safer wrapper for paste(..., sep = " and ")
35
46
# '
36
47
# ' The intent is to use this for readability when combining XPath conditions so
@@ -40,7 +51,7 @@ xml_nodes_to_lint <- function(xml, source_file, lint_message,
40
51
# '
41
52
# ' @param ... Series of conditions
42
53
# ' @noRd
43
- xp_and <- function (... ) sprintf( " (%s) " , paste( ... , sep = " ) and ( " ) )
54
+ xp_and <- function (... ) paren_wrap( ... , sep = " and" )
44
55
45
56
# ' Safer wrapper for paste(..., sep = " or ")
46
57
# '
@@ -51,4 +62,4 @@ xp_and <- function(...) sprintf("(%s)", paste(..., sep = ") and ("))
51
62
# '
52
63
# ' @param ... Series of conditions
53
64
# ' @noRd
54
- xp_or <- function (... ) sprintf( " (%s) " , paste( ... , sep = " ) or ( " ) )
65
+ xp_or <- function (... ) paren_wrap( ... , sep = " or " )
0 commit comments