From e1f3afa9555e83971900c54958d5da10f4d46928 Mon Sep 17 00:00:00 2001 From: Emily de la Rua Date: Thu, 20 Feb 2025 11:04:14 -0500 Subject: [PATCH 1/7] Fix bug --- R/tt_pos_and_access.R | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/R/tt_pos_and_access.R b/R/tt_pos_and_access.R index 127f678c9..c8a18347b 100644 --- a/R/tt_pos_and_access.R +++ b/R/tt_pos_and_access.R @@ -579,9 +579,15 @@ setMethod( curkid <- nxtval value <- value[-1] } else { - rvs <- row_values(curkid) - rvs[j] <- value[seq_along(j)] - row_values(curkid) <- rvs + if (is(nxtval, "CellValue")) { + rcs <- row_cells(curkid) + rcs[j] <- value[seq_along(j)] + row_cells(curkid) <- rcs + } else{ + rvs <- row_values(curkid) + rvs[j] <- value[seq_along(j)] + row_values(curkid) <- rvs + } value <- value[-(seq_along(j))] } kids[[pos]] <- curkid From 75eba201202fbd2d36dfef9a5d3eda45ccf4bc20 Mon Sep 17 00:00:00 2001 From: Emily de la Rua Date: Thu, 20 Feb 2025 11:05:14 -0500 Subject: [PATCH 2/7] Update example --- R/tt_pos_and_access.R | 2 +- man/brackets.Rd | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/R/tt_pos_and_access.R b/R/tt_pos_and_access.R index c8a18347b..2545a7682 100644 --- a/R/tt_pos_and_access.R +++ b/R/tt_pos_and_access.R @@ -467,7 +467,7 @@ setMethod( #' tbl[, -1] #' #' # Values can be reassigned -#' tbl[2, 1] <- rcell(999) +#' tbl[4, 2] <- rcell(999, format = "xx.x") #' tbl[2, ] <- list(rrow("FFF", 888, 666, 777)) #' tbl[6, ] <- list(-111, -222, -333) #' tbl diff --git a/man/brackets.Rd b/man/brackets.Rd index 6426ccf95..d550fa324 100644 --- a/man/brackets.Rd +++ b/man/brackets.Rd @@ -94,7 +94,7 @@ tbl[-2, ] tbl[, -1] # Values can be reassigned -tbl[2, 1] <- rcell(999) +tbl[4, 2] <- rcell(999, format = "xx.x") tbl[2, ] <- list(rrow("FFF", 888, 666, 777)) tbl[6, ] <- list(-111, -222, -333) tbl From d1a28df7dcb209482d73b0ece015263f1843575f Mon Sep 17 00:00:00 2001 From: Emily de la Rua Date: Thu, 20 Feb 2025 11:05:26 -0500 Subject: [PATCH 3/7] Add project ID --- rtables.Rproj | 1 + 1 file changed, 1 insertion(+) diff --git a/rtables.Rproj b/rtables.Rproj index d574f8263..5793e7bd3 100644 --- a/rtables.Rproj +++ b/rtables.Rproj @@ -1,4 +1,5 @@ Version: 1.0 +ProjectId: 4d2c3c80-3618-40eb-b805-a291cb9acbf6 RestoreWorkspace: Default SaveWorkspace: Default From bddd0bcfa68f4dea146d76f7f3f9586755b31c07 Mon Sep 17 00:00:00 2001 From: Emily de la Rua Date: Thu, 20 Feb 2025 11:19:20 -0500 Subject: [PATCH 4/7] Add tests --- tests/testthat/test-subset-access.R | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/tests/testthat/test-subset-access.R b/tests/testthat/test-subset-access.R index f136dc6ef..09465b53a 100644 --- a/tests/testthat/test-subset-access.R +++ b/tests/testthat/test-subset-access.R @@ -376,9 +376,31 @@ test_that("setters work ok", { cell_values(tbl4)[["U.AGE.mean"]], list(5, 7, 8) ) + + tbl5 <- tbl + tbl5[4, 1] <- rcell(999, format = "xx.xx") + tbl5[5, 2] <- list(c(3, 0.25)) + tbl5[5, 3] <- rcell(NA, format_na_str = "") + tbl5[6, ] <- list(-111, -222, -333) + matform5 <- matrix_form(tbl5) + expect_identical( + c("mean", "999.00", "32.1", "34.2794117647059"), + mf_strings(matform5)[5, ] + ) + expect_identical( + c("U", "0 (0.0%)", "3 (25.0%)", ""), + mf_strings(matform5)[6, ] + ) + expect_identical( + c("mean", "-111", "-222", "-333"), + mf_strings(matform5)[7, ] + ) + expect_identical( + c("", "xx.xx", "xx", "xx"), + mf_formats(matform5)[5, ] + ) }) - test_that("cell_values and value_at work on row objects", { tbl <- basic_table() %>% split_cols_by("ARM") %>% From 801c649a099dd2f000e730b5073a7c2ec1e4969a Mon Sep 17 00:00:00 2001 From: Emily de la Rua Date: Thu, 20 Feb 2025 16:13:39 -0500 Subject: [PATCH 5/7] Update NEWS --- NEWS.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 62e73ab1f..db1427f90 100644 --- a/NEWS.md +++ b/NEWS.md @@ -7,7 +7,8 @@ ### Bug Fixes * Fixed issue with `split_cols_by_multivar()` when having more than one value. Now `as_result_df(make_ard = TRUE)` adds a predefined split name for each of the `multivar` splits. * Fixed bug happening when format functions were changing the number of printed values. Now `as_result_df(make_ard = TRUE)` uses the cell values for `stat_strings` for these exceptions. - + * Fixed bug in `[<-` causing information to be stripped from other cells if a new `rcell` is set within a table row. + ## rtables 0.6.11 ### New Features From 993f32d34f40c020f342b132ee912acb46f4ebdf Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 20 Feb 2025 21:16:43 +0000 Subject: [PATCH 6/7] [skip style] [skip vbump] Restyle files --- R/tt_pos_and_access.R | 6 +++--- tests/testthat/test-subset-access.R | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/R/tt_pos_and_access.R b/R/tt_pos_and_access.R index 2545a7682..2054d33b3 100644 --- a/R/tt_pos_and_access.R +++ b/R/tt_pos_and_access.R @@ -582,11 +582,11 @@ setMethod( if (is(nxtval, "CellValue")) { rcs <- row_cells(curkid) rcs[j] <- value[seq_along(j)] - row_cells(curkid) <- rcs - } else{ + row_cells(curkid) <- rcs + } else { rvs <- row_values(curkid) rvs[j] <- value[seq_along(j)] - row_values(curkid) <- rvs + row_values(curkid) <- rvs } value <- value[-(seq_along(j))] } diff --git a/tests/testthat/test-subset-access.R b/tests/testthat/test-subset-access.R index 09465b53a..02f196c2e 100644 --- a/tests/testthat/test-subset-access.R +++ b/tests/testthat/test-subset-access.R @@ -376,7 +376,7 @@ test_that("setters work ok", { cell_values(tbl4)[["U.AGE.mean"]], list(5, 7, 8) ) - + tbl5 <- tbl tbl5[4, 1] <- rcell(999, format = "xx.xx") tbl5[5, 2] <- list(c(3, 0.25)) @@ -384,15 +384,15 @@ test_that("setters work ok", { tbl5[6, ] <- list(-111, -222, -333) matform5 <- matrix_form(tbl5) expect_identical( - c("mean", "999.00", "32.1", "34.2794117647059"), + c("mean", "999.00", "32.1", "34.2794117647059"), mf_strings(matform5)[5, ] ) expect_identical( - c("U", "0 (0.0%)", "3 (25.0%)", ""), + c("U", "0 (0.0%)", "3 (25.0%)", ""), mf_strings(matform5)[6, ] ) expect_identical( - c("mean", "-111", "-222", "-333"), + c("mean", "-111", "-222", "-333"), mf_strings(matform5)[7, ] ) expect_identical( From f2d8079f7f517cd4370d9ecea1428aa839fd1b17 Mon Sep 17 00:00:00 2001 From: Emily de la Rua Date: Thu, 20 Feb 2025 16:37:52 -0500 Subject: [PATCH 7/7] Fix lint --- R/tt_pos_and_access.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/tt_pos_and_access.R b/R/tt_pos_and_access.R index 2054d33b3..629e3d4df 100644 --- a/R/tt_pos_and_access.R +++ b/R/tt_pos_and_access.R @@ -50,7 +50,7 @@ recursive_replace <- function(tab, path, value) { ## incontent = FALSE, rows = N ## newkid[rows, cols] = value ## } ## } - return(newkid) + newkid } else if (path[[1]] == "@content") { ctb <- content_table(tab) ctb <- recursive_replace(ctb,