diff --git a/R/utils.R b/R/utils.R index 13ee6205..6d01c23e 100644 --- a/R/utils.R +++ b/R/utils.R @@ -96,7 +96,12 @@ split_on_line_directives <- function(lines) { file_starts <- directive_lines + 1 file_ends <- c(directive_lines[-1] - 1, length(lines)) - res <- mapply(function(start, end) lines[start:end], file_starts, file_ends) + res <- mapply( + function(start, end) lines[start:end], + file_starts, + file_ends, + SIMPLIFY = FALSE + ) names(res) <- na.omit(matches$filename) res } diff --git a/tests/testthat/test-utils.R b/tests/testthat/test-utils.R index 8ee62041..90dc0a37 100644 --- a/tests/testthat/test-utils.R +++ b/tests/testthat/test-utils.R @@ -72,3 +72,34 @@ test_that("split_on_line_directives returns NULL for input without directive (#5 NULL ) }) + +test_that("split_on_line_directives does not simplify the result (#588)", { + expect_identical( + split_on_line_directives( + c( + '#line 1 "foo.R"', + "abc", + "def" + ) + ), + list( + "foo.R" = c("abc", "def") + ) + ) + expect_identical( + split_on_line_directives( + c( + '#line 1 "foo.R"', + "abc", + "def", + '#line 4 "bar.R"', + "ghi", + "jkl" + ) + ), + list( + "foo.R" = c("abc", "def"), + "bar.R" = c("ghi", "jkl") + ) + ) +})