Skip to content

Commit 287c756

Browse files
fix
1 parent 86daefa commit 287c756

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

R/rules-line-breaks.R

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -457,11 +457,19 @@ reduce_extra_blank_lines_between_scopes <- function(pd_flat, allowed_blank_lines
457457
# Calculate the maximum allowed lag_newlines
458458
max_lag_newlines <- allowed_blank_lines + 1L # +1 accounts for the line with the previous token
459459

460-
# Identify positions where lag_newlines exceed the maximum allowed
461-
idx <- which(pd_flat$lag_newlines > max_lag_newlines)
460+
# Create a copy of lag_newlines to track modifications
461+
modified_lag_newlines <- pd_flat$lag_newlines
462462

463-
# Reduce lag_newlines to the maximum allowed at those positions
464-
pd_flat$lag_newlines[idx] <- max_lag_newlines
463+
# Iterate through the dataframe to reduce consecutive blank lines
464+
for (i in seq_along(modified_lag_newlines)) {
465+
if (modified_lag_newlines[i] > max_lag_newlines) {
466+
modified_lag_newlines[i] <- max_lag_newlines
467+
}
468+
}
469+
470+
# Update the original data frame
471+
pd_flat$lag_newlines <- modified_lag_newlines
465472

466473
return(pd_flat)
467474
}
475+

0 commit comments

Comments
 (0)