From d37ac25bc6135b5ce5c91d3ff02e302bb962daf7 Mon Sep 17 00:00:00 2001 From: Jenny Bryan Date: Wed, 12 Sep 2018 16:28:16 -0700 Subject: [PATCH] Ignore empty lines when trimming common leading whitespace --- R/utils.R | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/R/utils.R b/R/utils.R index bbc4aa1a..ad476681 100644 --- a/R/utils.R +++ b/R/utils.R @@ -26,8 +26,9 @@ trim_ws <- function(x) { trim_common_leading_ws <- function(x) { m <- regexpr("^(\\s*)", x) - ws <- regmatches(x, m) - num <- min(nchar(ws)) + n_chars <- nchar(x) + n_spaces <- attr(m, which = "match.length") + num <- min(n_spaces[n_chars > 0]) substring(x, num + 1) }