Skip to content

Commit 1fdd0ad

Browse files
authored
Merge pull request #76 from metrumresearchgroup/fix/split_long_rows
Fix: `split_long_rows` when no mappings occur
2 parents 0a71124 + 8e362bd commit 1fdd0ad

File tree

3 files changed

+46
-4
lines changed

3 files changed

+46
-4
lines changed

.github/workflows/main.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ jobs:
3535
r-version: ${{ matrix.config.r }}
3636
use-public-rspm: true
3737
extra-repositories: 'https://mpn.metworx.com/snapshots/stable/${{ env.MPN_LATEST }}'
38+
- name: Install additional system dependencies
39+
shell: bash
40+
run: sudo apt-get install libpoppler-cpp-dev
3841
- uses: r-lib/actions/setup-r-dependencies@v2
3942
with:
4043
extra-packages: |
@@ -61,6 +64,9 @@ jobs:
6164
r-version: release
6265
use-public-rspm: true
6366
extra-repositories: 'https://mpn.metworx.com/snapshots/stable/${{ env.MPN_LATEST }}'
67+
- name: Install additional system dependencies
68+
shell: bash
69+
run: sudo apt-get install libpoppler-cpp-dev
6470
- uses: r-lib/actions/setup-r-dependencies@v2
6571
with:
6672
extra-packages: any::pkgpub

R/format-report.R

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -818,12 +818,17 @@ split_long_rows <- function(exported_func_df, n = 40) {
818818
# Expand each row if any of the splits are greater than 1
819819
dplyr::group_split() %>%
820820
purrr::map_dfr(function(row_data) {
821-
n_chunks <- max(length(row_data$code_file_split[[1]]),
822-
length(row_data$documentation_split[[1]]),
823-
length(row_data$test_files_split[[1]]))
821+
n_chunks <- max(
822+
length(row_data$code_file_split[[1]]),
823+
length(row_data$documentation_split[[1]]),
824+
length(row_data$test_files_split[[1]]),
825+
# Ensure the minimum value is at least 1
826+
# i.e. when columns code_file, documentation, and test_files are all empty
827+
1
828+
)
824829

825830
# Create a list of new rows
826-
purrr::map_dfr(1:n_chunks, function(i) {
831+
purrr::map_dfr(seq_len(n_chunks), function(i) {
827832
new_row <- row_data
828833

829834
# Extract split contents or default to an empty string

tests/testthat/test-format-report.R

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,37 @@ describe("formatting functions", {
215215
expect_true(all(grepl(paste(81:100, collapse = "|"), strsplit(exported_func_df[3,]$`Test Files`, "\n")[[1]])))
216216
})
217217

218+
it("split_long_rows", {
219+
# Other formatting is done in format_traceability_matrix before
220+
# split_long_rows is called. Integration test will suffice
221+
mock_exports_df <- tibble::tibble(
222+
exported_function = "example_func",
223+
code_file = list("R/example_func.R"),
224+
documentation = list("man/example_func.Rd"),
225+
test_files = list(rep("test-example_func.R", 60)),
226+
test_dirs = list(NULL)
227+
)
228+
229+
mock_exports_flex <- format_traceability_matrix(mock_exports_df)
230+
mock_exports_split <- tibble::as_tibble(mock_exports_flex$body$dataset)
231+
expect_equal(
232+
mock_exports_split$`Exported Function`,
233+
c("example_func", "example_func (cont.)")
234+
)
235+
# Default cutoff for making a new export is 40, so there should be 39 rows
236+
expect_equal(stringr::str_count(mock_exports_split$`Test Files`[1], "\n"), 39)
237+
238+
# Regression test: works when other columns are empty
239+
# - This occurred when columns `code_file`, `documentation`, and `test_files`
240+
# were _all_ empty
241+
mock_exports_df$code_file <- list(NA_character_)
242+
mock_exports_df$documentation <- list(NA_character_)
243+
mock_exports_df$test_files <- list(NA_character_)
244+
mock_exports_flex <- format_traceability_matrix(mock_exports_df)
245+
mock_exports_split <- tibble::as_tibble(mock_exports_flex$body$dataset)
246+
expect_equal(mock_exports_split$`Exported Function`, "example_func")
247+
})
248+
218249
it("format_appendix", {
219250
pkg_setup_select <- pkg_dirs$pkg_setups_df %>% dplyr::filter(pkg_type == "pass_success")
220251
result_dir_x <- pkg_setup_select$pkg_result_dir

0 commit comments

Comments
 (0)