Skip to content

Commit 00125f0

Browse files
Merge pull request #809 from lorenzwalthert/issue-808
- Only remove excessive line breaks in assignments (#809).
2 parents 9d376c4 + 4a74bfe commit 00125f0

File tree

5 files changed

+110
-8
lines changed

5 files changed

+110
-8
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@
5959
code header anymore. This can be handy when the code can't be parsed, e.g.
6060
within a learnr tutorial (#790).
6161
* `#>` is recognized as an output marker and no space is added after `#` (#771).
62+
* multi-expressions containing multiple assignments no longer remove line breaks
63+
if they are not causing blank lines (#809).
6264
* R code chunks in nested non-R chunks in R markdown don't yield an error
6365
anymore when document is styled, chunks are still not styled (#788, #794).
6466
* `cache_activate()` and `cache_deactivate()` now respect the R

R/rules-line-breaks.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ add_line_break_after_pipe <- function(pd) {
201201
set_line_break_after_assignment <- function(pd) {
202202
is_assignment <- lag(pd$token, default = FALSE) %in% c("LEFT_ASSIGN", "EQ_ASSIGN")
203203
if (any(is_assignment)) {
204-
pd$lag_newlines[is_assignment] <- min(1L, pd$lag_newlines[is_assignment])
204+
pd$lag_newlines[is_assignment] <- pmin(1L, pd$lag_newlines[is_assignment])
205205
}
206206
pd
207207
}

tests/testthat/line_breaks_and_other/assignment-in.R

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,19 @@ x =
2222

2323
# comment
2424
3
25+
26+
27+
28+
ImportantDataFrame$ImportantColumn1 <-
29+
ImportantDataFrame$ImportantColumn2 <-
30+
ComplicatedFunction(ImportantDataFrame$InputColumn)
31+
32+
33+
ImportantDataFrame$ImportantColumn1 <-
34+
ImportantDataFrame$ImportantColumn2 <- ComplicatedFunction(ImportantDataFrame$InputColumn)
35+
36+
37+
38+
ImportantDataFrame$ImportantColumn1 <-
39+
40+
ImportantDataFrame$ImportantColumn2 <- ComplicatedFunction(ImportantDataFrame$InputColumn)

tests/testthat/line_breaks_and_other/assignment-in_tree

Lines changed: 76 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/line_breaks_and_other/assignment-out.R

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,18 @@ x <- 3
2121
x <-
2222
# comment
2323
3
24+
25+
26+
27+
ImportantDataFrame$ImportantColumn1 <-
28+
ImportantDataFrame$ImportantColumn2 <-
29+
ComplicatedFunction(ImportantDataFrame$InputColumn)
30+
31+
32+
ImportantDataFrame$ImportantColumn1 <-
33+
ImportantDataFrame$ImportantColumn2 <- ComplicatedFunction(ImportantDataFrame$InputColumn)
34+
35+
36+
37+
ImportantDataFrame$ImportantColumn1 <-
38+
ImportantDataFrame$ImportantColumn2 <- ComplicatedFunction(ImportantDataFrame$InputColumn)

0 commit comments

Comments
 (0)