From 7ec7f13b4de38d757f3e7e2d795832775b1514a5 Mon Sep 17 00:00:00 2001 From: Kyle Baron Date: Fri, 13 May 2022 16:39:57 -0500 Subject: [PATCH 01/17] new dev version --- DESCRIPTION | 2 +- NEWS.md | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index d411bc2b..a4b84d9a 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: pmtables Type: Package Title: Tables for Pharmacometrics -Version: 0.5.0 +Version: 0.5.0.9000 Authors@R: c( person(given = "Kyle", diff --git a/NEWS.md b/NEWS.md index 0eb752c9..7407bdfb 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,5 @@ +# pmtables (development version) + # pmtables 0.5.0 - New functions `st_as_image()`, `st2pdf()`, and `st2png()` to render tables with From b4e80c2aca26d66814c53b066afffbcbb26a98a5 Mon Sep 17 00:00:00 2001 From: Kyle Baron Date: Sun, 29 May 2022 16:22:16 -0500 Subject: [PATCH 02/17] adds comments around hlines for detached notes --- DESCRIPTION | 2 +- R/table-notes.R | 6 +++++- inst/validation/build-validation-docs.R | 4 ++-- tests/testthat/validate/notes-mini.tex | 2 ++ tests/testthat/validate/validate.pdf | Bin 147956 -> 147956 bytes 5 files changed, 10 insertions(+), 4 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index a4b84d9a..cd8e0872 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -36,7 +36,7 @@ Suggests: testthat, yaml, fs, texPreview, magick, pdftools Encoding: UTF-8 Language: en-US LazyData: true -RoxygenNote: 7.1.2 +RoxygenNote: 7.2.0 Roxygen: list(markdown = TRUE) VignetteBuilder: knitr Collate: diff --git a/R/table-notes.R b/R/table-notes.R index ca3934d8..64aee69c 100644 --- a/R/table-notes.R +++ b/R/table-notes.R @@ -108,7 +108,11 @@ noteconf <- function(width = 0.8, is.noteconfig <- function(x) inherits(x, "noteconfig") mini_notes <- function(notes, x) { - hline1 <- hline2 <- paste0("\\rule{", 1, "\\linewidth}{",x$hline_pt, "pt}") + hline1 <- hline2 <- c( + "%", + paste0("\\rule{", 1, "\\linewidth}{",x$hline_pt, "pt}"), + "%" + ) tskip <- paste0("\\vskip ", x$table_skip, "cm") nskip <- paste0("\\vskip ", x$note_skip, "cm") if(!x$hline1) { diff --git a/inst/validation/build-validation-docs.R b/inst/validation/build-validation-docs.R index 36be5204..a77991bf 100644 --- a/inst/validation/build-validation-docs.R +++ b/inst/validation/build-validation-docs.R @@ -12,11 +12,11 @@ ####################################################### PKGNAME <- "pmtables" -PKGVERSION <- "0.4.1.9003" +PKGVERSION <- "0.5.0" STYLE_REF_DIR <- "docx-ref-header-image" # set to NULL if not using style ref # set up directories and clear existing output dirs, if they exist -val_dir <- system.file("validation", package = PKGNAME) +val_dir <- getwd() # system.file("validation", package = PKGNAME) print(val_dir) style_ref_path <- NULL diff --git a/tests/testthat/validate/notes-mini.tex b/tests/testthat/validate/notes-mini.tex index f23c4c44..e738b62b 100644 --- a/tests/testthat/validate/notes-mini.tex +++ b/tests/testthat/validate/notes-mini.tex @@ -24,7 +24,9 @@ \vskip 0.67cm \begin{minipage}{0.8\linewidth} \linespread{1.1}\selectfont +% \rule{1\linewidth}{0.4pt} +% \vskip 0.02cm WT: weight \newline ALB: albumin \newline diff --git a/tests/testthat/validate/validate.pdf b/tests/testthat/validate/validate.pdf index d1ecc04563e5b6c570fa5a48cfa07e425d0fcd0c..0a139e2f0e7f8194078e53df8a09ce8e271a2f00 100644 GIT binary patch delta 141 zcmey;%=x96v!R7?3)2K0eN!V#Lo*`-V`E(dQ*{FabxkgP-~1Gp#FA764HqjT10y2? zWF_18>oCm|aCUYwvotkxc64)fu`o7wGj=m{b#pRtaxycsa4|J^GO$yyA*5vc0$ZjK F765AhBn|)o delta 141 zcmey;%=x96v!R7?3)2K0ePcr-Lt_(j6BAtnGj#(4bxkgP-~1Gp#FA764HqjT10y2? zWF_18>oCm|a5ghDH8FN_a=bMWDcQcjmMMe< E07cm&LI3~& From f83f3c0f2f020115a8f043054b416bcb0f839c17 Mon Sep 17 00:00:00 2001 From: Kyle Baron Date: Sun, 29 May 2022 17:00:21 -0500 Subject: [PATCH 03/17] data inventory - fix all data name and add summarize optoin --- DESCRIPTION | 2 +- R/data_inventory_table.R | 34 +++++++++++++++------------ man/data_inventory_data.Rd | 4 ++++ man/pt_data_inventory.Rd | 10 +++++++- tests/testthat/validate/validate.pdf | Bin 147956 -> 147956 bytes 5 files changed, 33 insertions(+), 17 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index a4b84d9a..cd8e0872 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -36,7 +36,7 @@ Suggests: testthat, yaml, fs, texPreview, magick, pdftools Encoding: UTF-8 Language: en-US LazyData: true -RoxygenNote: 7.1.2 +RoxygenNote: 7.2.0 Roxygen: list(markdown = TRUE) VignetteBuilder: knitr Collate: diff --git a/R/data_inventory_table.R b/R/data_inventory_table.R index 305124fb..9eab03ba 100644 --- a/R/data_inventory_table.R +++ b/R/data_inventory_table.R @@ -26,7 +26,7 @@ data_inventory_chunk <- function(data, by, panel = by, stacked = FALSE, ...) { if(by==".total" | panel == ".total") { - data <- data_total_col(data,all_name = all_name) + data <- data_total_col(data, all_name = all_name) } miss <- FALSE @@ -134,7 +134,7 @@ data_inventory_data_split <- function(data,by,panel=by,stacked=FALSE,...) { #' #' @export data_inventory_data <- function(data, by, panel = by, all_name = "all", - stacked = FALSE, ...) { + summarize_all = TRUE, stacked = FALSE, ...) { by <- unname(by) panel <- unname(panel) @@ -156,7 +156,7 @@ data_inventory_data <- function(data, by, panel = by, all_name = "all", ... ) - if(by != ".total") { + if(by != ".total" && isTRUE(summarize_all)) { tot <- data_inventory_chunk( data, by = ".total", @@ -229,6 +229,10 @@ pt_data_study <- function(data, study_col = "STUDY", panel = study_col, ...) { #' `MISS` values are equal to zero. #' @param stacked If `TRUE`, then independent summaries are created by `outer` #' and included in a single table (see examples). +#' @param summarize_all if `TRUE` then a complete data summary will be +#' appended to the bottom of the table when `stacked` is `FALSE`. +#' @param all_name_stacked a name to use for the complete data summary when +#' `stacked` is `TRUE`. #' @param dv_col Character name of `DV` column. #' @param bq_col Character name of `BQL` column; see [find_bq_col()]. #' @param id_col Character name of `ID` column. @@ -300,12 +304,17 @@ pt_data_study <- function(data, study_col = "STUDY", panel = study_col, ...) { pt_data_inventory <- function(data, by = ".total", panel = by, inner_summary = TRUE, drop_miss = FALSE, stacked = FALSE, table = NULL, - all_name = "all", + summarize_all = TRUE, + all_name = "All data", + all_name_stacked = "Group Total", dv_col = "DV", bq_col = find_bq_col(data), id_col = "ID", ...) { + stacked <- isTRUE(stacked) + if(stacked) all_name <- all_name_stacked + has_panel <- !missing(panel) panel_data <- as.panel(panel) panel <- panel_data$col @@ -328,8 +337,8 @@ pt_data_inventory <- function(data, by = ".total", panel = by, } total_name <- case_when( - isTRUE(stacked) ~ "\\hline {\\it Group Total}", - TRUE ~ "\\hline \\hline {\\bf All data}" + stacked ~ paste0("\\hline {\\it ", all_name, "}"), + TRUE ~ paste0("\\hline \\hline {\\bf ", all_name, "}") ) ans <- data_inventory_data( @@ -338,13 +347,14 @@ pt_data_inventory <- function(data, by = ".total", panel = by, panel = panel, stacked = stacked, all_name = all_name, + summarize_all = summarize_all, dv_col = dv_col, bq_col = bq_col, id_col = id_col, ... ) - if(exists(by,ans)) { + if(exists(by, ans)) { ans <- mutate( ans, !!sym(by) := ifelse(!!sym(by)==".total", total_name, !!sym(by)) @@ -365,7 +375,7 @@ pt_data_inventory <- function(data, by = ".total", panel = by, `Percent.OBS` = .data[["OOBS"]], `Percent.BQL` = .data[["OBQL"]] ) - ans <- mutate(ans,POBS=NULL,PBQL=NULL) + ans <- mutate(ans, POBS = NULL, PBQL = NULL) } ans <- rename( @@ -384,7 +394,7 @@ pt_data_inventory <- function(data, by = ".total", panel = by, ans <- mutate(ans, Number.MISS = NULL) } - ans <- mutate(ans,.total = NULL) + ans <- mutate(ans, .total = NULL) out <- ans notes <- pt_data_inventory_notes(bq = bq_col, drop_bql = drop_bql) @@ -396,8 +406,6 @@ pt_data_inventory <- function(data, by = ".total", panel = by, out <- select(out, !contains("BQL")) } - .sumrows <- NULL - .panel <- rowpanel(NULL) if(has_panel) { .panel <- panel_data @@ -406,10 +414,6 @@ pt_data_inventory <- function(data, by = ".total", panel = by, if(panel==by) panel <- NULL - if(!stacked & isTRUE(has_by)) { - .sumrows <- sumrow(out[,1]==total_name, bold = TRUE) - } - out <- list( data = out, panel = .panel, diff --git a/man/data_inventory_data.Rd b/man/data_inventory_data.Rd index 569653ee..e406309f 100644 --- a/man/data_inventory_data.Rd +++ b/man/data_inventory_data.Rd @@ -9,6 +9,7 @@ data_inventory_data( by, panel = by, all_name = "all", + summarize_all = TRUE, stacked = FALSE, ... ) @@ -24,6 +25,9 @@ not add or remove rows prior to summarizing \code{data}} \item{all_name}{a name to use for the complete data summary} +\item{summarize_all}{if \code{TRUE} then a complete data summary will be +appended to the bottom of the table when \code{stacked} is \code{FALSE}.} + \item{stacked}{If \code{TRUE}, then independent summaries are created by \code{outer} and included in a single table (see examples).} diff --git a/man/pt_data_inventory.Rd b/man/pt_data_inventory.Rd index 20e51269..2c974691 100644 --- a/man/pt_data_inventory.Rd +++ b/man/pt_data_inventory.Rd @@ -12,7 +12,9 @@ pt_data_inventory( drop_miss = FALSE, stacked = FALSE, table = NULL, - all_name = "all", + summarize_all = TRUE, + all_name = "All data", + all_name_stacked = "Group Total", dv_col = "DV", bq_col = find_bq_col(data), id_col = "ID", @@ -40,8 +42,14 @@ and included in a single table (see examples).} \item{table}{a named list to use for renaming columns (see details and examples)} +\item{summarize_all}{if \code{TRUE} then a complete data summary will be +appended to the bottom of the table when \code{stacked} is \code{FALSE}.} + \item{all_name}{a name to use for the complete data summary} +\item{all_name_stacked}{a name to use for the complete data summary when +\code{stacked} is \code{TRUE}.} + \item{dv_col}{Character name of \code{DV} column.} \item{bq_col}{Character name of \code{BQL} column; see \code{\link[=find_bq_col]{find_bq_col()}}.} diff --git a/tests/testthat/validate/validate.pdf b/tests/testthat/validate/validate.pdf index d1ecc04563e5b6c570fa5a48cfa07e425d0fcd0c..20b665cbe07fff97202f7925a4d357c2015f6393 100644 GIT binary patch delta 140 zcmey;%=x96v!R7?3)2K0eN!V#Lo*X26H{FSQ*{FabxkgP-~1Gp#FA764HqjT10y2? zWF_18>oCm|a56GCH+3~|F?Y2zv2ZkUaW*kCcXl#%bultCGB9v9GO|;!A)sXYd|Rea F762{_BO?F+ delta 140 zcmey;%=x96v!R7?3)2K0ePcr-Lt_(j6BAtnGj#(4bxkgP-~1Gp#FA764HqjT10y2? zWF_18>oCm|a56J9H8FN_a=bMWDA_*WmMN44 E03!_}4*&oF From 003eb523c8f3d49d5e74fe487fe00560181dec0d Mon Sep 17 00:00:00 2001 From: Kyle Baron Date: Thu, 28 Jul 2022 12:59:25 -0400 Subject: [PATCH 04/17] tskip working on metworx --- R/table-notes.R | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/R/table-notes.R b/R/table-notes.R index 64aee69c..8e30a021 100644 --- a/R/table-notes.R +++ b/R/table-notes.R @@ -109,12 +109,10 @@ is.noteconfig <- function(x) inherits(x, "noteconfig") mini_notes <- function(notes, x) { hline1 <- hline2 <- c( - "%", - paste0("\\rule{", 1, "\\linewidth}{",x$hline_pt, "pt}"), - "%" + paste0("\\rule{", 1, "\\linewidth}{",x$hline_pt, "pt}") ) - tskip <- paste0("\\vskip ", x$table_skip, "cm") - nskip <- paste0("\\vskip ", x$note_skip, "cm") + tskip <- paste0("\\vspace{", x$table_skip, "cm}") + nskip <- paste0("\\vspace{", x$note_skip, "cm}") if(!x$hline1) { hline1 <- NULL } @@ -123,7 +121,9 @@ mini_notes <- function(notes, x) { } notes <- paste(notes, "\\newline") out <- c( + " ", tskip, + " ", paste0("\\begin{minipage}{",x$width,"\\linewidth}"), paste0("\\linespread{1.1}\\selectfont"), hline1, From f0d90689b04be2894016121661e44e5f93b65a88 Mon Sep 17 00:00:00 2001 From: Kyle Baron Date: Thu, 28 Jul 2022 12:30:09 -0500 Subject: [PATCH 05/17] re-run validation --- tests/testthat/validate/notes-mini.tex | 8 ++++---- tests/testthat/validate/validate.pdf | Bin 147956 -> 147956 bytes 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/testthat/validate/notes-mini.tex b/tests/testthat/validate/notes-mini.tex index e738b62b..f7986be5 100644 --- a/tests/testthat/validate/notes-mini.tex +++ b/tests/testthat/validate/notes-mini.tex @@ -21,13 +21,13 @@ \hline \end{tabular} \end{threeparttable} -\vskip 0.67cm + +\vspace{0.67cm} + \begin{minipage}{0.8\linewidth} \linespread{1.1}\selectfont -% \rule{1\linewidth}{0.4pt} -% -\vskip 0.02cm +\vspace{0.02cm} WT: weight \newline ALB: albumin \newline \end{minipage} diff --git a/tests/testthat/validate/validate.pdf b/tests/testthat/validate/validate.pdf index 0a139e2f0e7f8194078e53df8a09ce8e271a2f00..a364254a58cf6ab0bc628f5b90d61cf401665b0e 100644 GIT binary patch delta 199 zcmey;%=x96bHg$zxpg5Wd;Nt(r`~3$pXyoc-?Zd)+Oic6UMZ_y9}+b+nS5Bvh}mT4 zi^)HwDp>w(V$Pm?&{Md%L%O{~nsIxFG!uuQj=7PAp^=fLsfn(Esk(uIx+a&tZ+?nP zVo9okhKrSvfsv5`T*>x5I!p@%oZZX}ja|$g-JD!4ES=1a&CSe>Oq|>dOkGV4&0XCL ROzaeF2r1dVz?Lb51pswsJq`c> delta 199 zcmey;%=x96bHg$z*{Xmus#;px8UJZbem0NA^ZHqzz{V*jLax6|I4Nv3`G}Mei;DTA zrpZ60Dp>l?GY3pQ=qcRXA>G~~&A7conu$YD$JEHu(9Fod*jU%VRNcTpU6V`SH$TNC zu_RSN!^O(Tz{tn|u4MZj9j1i>&dyF|mZoOTj&80l7RKgo#%_kLZcZjnPG)8nE~e&A R26hTIgp_PwV9ON30st~kJm>%b From 996bcbaacff5763773f467ccd335f777bb8070d0 Mon Sep 17 00:00:00 2001 From: Kyle Baron Date: Thu, 28 Jul 2022 14:03:28 -0500 Subject: [PATCH 06/17] add tests --- R/data_inventory_table.R | 9 +++--- inst/validation/pmtables-stories.yaml | 17 +++++++++++ tests/testthat/test-inventory-table.R | 41 +++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 4 deletions(-) diff --git a/R/data_inventory_table.R b/R/data_inventory_table.R index 9eab03ba..f863c5a2 100644 --- a/R/data_inventory_table.R +++ b/R/data_inventory_table.R @@ -336,10 +336,11 @@ pt_data_inventory <- function(data, by = ".total", panel = by, inner_summary <- FALSE } - total_name <- case_when( - stacked ~ paste0("\\hline {\\it ", all_name, "}"), - TRUE ~ paste0("\\hline \\hline {\\bf ", all_name, "}") - ) + if(stacked) { + total_name <- paste0("\\hline {\\it ", all_name, "}") + } else { + total_name <- paste0("\\hline \\hline {\\bf ", all_name, "}") + } ans <- data_inventory_data( data, diff --git a/inst/validation/pmtables-stories.yaml b/inst/validation/pmtables-stories.yaml index 8caa1933..2740ee42 100644 --- a/inst/validation/pmtables-stories.yaml +++ b/inst/validation/pmtables-stories.yaml @@ -1,4 +1,21 @@ # Please add user stories at the top of this file +PMT-S081: + name: Customize All Data summary in pt inventory table + description: > + As a user, I want to customize the label on All Data summary in + pt_data_inventory. + ProductRisk: low-risk + tests: + - PMT-INVEN-0002 + - PMT-INVEN-0003 +PMT-S080: + name: Optional All Data summary on pt inventory table + description: > + As a user, I want to opt in to the All Data summary + in pt_data_inventory. + ProductRisk: medium-risk + tests: + - PMT-INVEN-0001 PMT-S079: name: sig returns character when passed integer description: > diff --git a/tests/testthat/test-inventory-table.R b/tests/testthat/test-inventory-table.R index 54797281..45147a3f 100644 --- a/tests/testthat/test-inventory-table.R +++ b/tests/testthat/test-inventory-table.R @@ -1,4 +1,5 @@ library(testthat) +library(pmtables) context("test-inventory-table") @@ -150,3 +151,43 @@ test_that("handle BQL and BLQ inventory table [PMT-TEST-0133]", { expect_equal(tab2$notes[3], "MISS: missing observations (non-BLQ)") expect_equal(tab3$notes[2], "MISS: missing observations") }) + +test_that("Optional All Data summary - inventory table [PMT-INVEN-0001]", { + a <- pt_data_inventory( + pmt_obs, + by = "STUDYf" + )$data + b <- pt_data_inventory( + pmt_obs, + by = "STUDYf", + summarize_all = FALSE + )$data + expect_identical(a[1:4,], b[1:4,]) + expect_true(nrow(a) == 1 + nrow(b)) +}) + +test_that("Change All Data name - inventory table [PMT-INVEN-0002]", { + a <- pt_data_inventory( + pmt_obs, + by = "STUDYf" + )$data + b <- pt_data_inventory( + pmt_obs, + by = "STUDYf", + all_name="ALL" + )$data + expect_match(a$STUDYf[5], "All") + expect_match(b$STUDYf[5], "ALL") +}) + +test_that("Change stacked group name - inventory table [PMT-INVEN-0003]", { + a <- pt_data_inventory( + pmt_obs, + by = "STUDYf", + stacked = TRUE, + panel = "SEQf", + all_name_stacked = "STACKED" + )$data + expect_match(a$STUDYf[5], "STACKED") + expect_match(a$STUDYf[11], "STACKED") +}) From d809d469a1a6990757eb3ed9901e9b43c5621133 Mon Sep 17 00:00:00 2001 From: Kyle Baron Date: Thu, 28 Jul 2022 14:30:47 -0500 Subject: [PATCH 07/17] ungroup data inventory data set --- R/data_inventory_table.R | 2 ++ 1 file changed, 2 insertions(+) diff --git a/R/data_inventory_table.R b/R/data_inventory_table.R index f863c5a2..a8af3949 100644 --- a/R/data_inventory_table.R +++ b/R/data_inventory_table.R @@ -312,6 +312,8 @@ pt_data_inventory <- function(data, by = ".total", panel = by, id_col = "ID", ...) { + data <- ungroup(data) + stacked <- isTRUE(stacked) if(stacked) all_name <- all_name_stacked From 095d767e5f6864569f6c24f8f26f1488a0b5f60b Mon Sep 17 00:00:00 2001 From: Kyle Baron Date: Thu, 28 Jul 2022 14:38:34 -0500 Subject: [PATCH 08/17] some type checks in data inventory --- R/data_inventory_table.R | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/R/data_inventory_table.R b/R/data_inventory_table.R index a8af3949..980438b5 100644 --- a/R/data_inventory_table.R +++ b/R/data_inventory_table.R @@ -312,10 +312,12 @@ pt_data_inventory <- function(data, by = ".total", panel = by, id_col = "ID", ...) { - data <- ungroup(data) - stacked <- isTRUE(stacked) if(stacked) all_name <- all_name_stacked + summarize_all <- isTRUE(summarize_all) + + assert_that(is.data.frame(data)) + data <- ungroup(as.data.frame(data)) has_panel <- !missing(panel) panel_data <- as.panel(panel) From 217aa9ec11412952830ea8aca2044e681d62986b Mon Sep 17 00:00:00 2001 From: Kyle Baron Date: Thu, 28 Jul 2022 14:54:47 -0500 Subject: [PATCH 09/17] fix test --- tests/testthat/test-notes.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/testthat/test-notes.R b/tests/testthat/test-notes.R index 3b8f3a2f..b7eeea28 100644 --- a/tests/testthat/test-notes.R +++ b/tests/testthat/test-notes.R @@ -34,8 +34,8 @@ test_that("mini notes [PMT-TEST-0154]", { expect_match(x$mini_notes,"abcd \\newline", fixed = TRUE, all = FALSE) expect_match(x$mini_notes,"xyz \\newline", fixed = TRUE, all = FALSE) expect_match(x$mini_notes,"end{minipage}", fixed = TRUE, all = FALSE) - expect_equal(x$mini_notes[1], "\\vskip 0.6cm", fixed = TRUE, all = FALSE) - expect_match(x$mini_notes, "\\vskip 0.1cm", fixed = TRUE, all = FALSE) + expect_equal(x$mini_notes[2], "\\vspace{0.6cm}", fixed = TRUE, all = FALSE) + expect_match(x$mini_notes, "\\vspace{0.1cm}", fixed = TRUE, all = FALSE) }) test_that("notes escape [PMT-TEST-0155]", { From 9ef7ae5074ffc244a2e841dfa5a6698076b18bd9 Mon Sep 17 00:00:00 2001 From: Kyle Baron Date: Thu, 28 Jul 2022 14:58:07 -0500 Subject: [PATCH 10/17] don't need to ungroup data after as.data.frame --- R/data_inventory_table.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/data_inventory_table.R b/R/data_inventory_table.R index 980438b5..71c58486 100644 --- a/R/data_inventory_table.R +++ b/R/data_inventory_table.R @@ -317,7 +317,7 @@ pt_data_inventory <- function(data, by = ".total", panel = by, summarize_all <- isTRUE(summarize_all) assert_that(is.data.frame(data)) - data <- ungroup(as.data.frame(data)) + data <- as.data.frame(data) has_panel <- !missing(panel) panel_data <- as.panel(panel) From f24cbac0dcc43bc11c4e130903188a6ac0a429e7 Mon Sep 17 00:00:00 2001 From: Kyle Baron Date: Tue, 2 Aug 2022 22:01:02 -0500 Subject: [PATCH 11/17] test for st_filter --- NAMESPACE | 1 + R/table-object.R | 28 +++++++++++++++++++++++++-- inst/validation/pmtables-stories.yaml | 7 +++++++ man/st_select.Rd | 23 ++++++++++++++++++++-- tests/testthat/test-table-object.R | 8 ++++++++ 5 files changed, 63 insertions(+), 4 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index 60405145..1ccda511 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -102,6 +102,7 @@ export(st_data) export(st_drop) export(st_edit) export(st_files) +export(st_filter) export(st_hline) export(st_image_show) export(st_it) diff --git a/R/table-object.R b/R/table-object.R index 932a8673..2b3483f5 100644 --- a/R/table-object.R +++ b/R/table-object.R @@ -867,8 +867,22 @@ st_drop <- function(x, ...) { #' These functions modify the input data frame prior to passing it to #' [stable()] or [stable_long()]. #' -#' @param x an stobject -#' @param ... passed to [dplyr::select()], or [dplyr::mutate()] +#' @param x an stobject. +#' @param ... passed to [dplyr::select()], [dplyr::mutate()], or +#' [dplyr::filter()]. +#' +#' @details +#' +#' - `st_select` calls `dplyr::select` on the data +#' - `st_mutate` calls `dplyr::mutate` on the data +#' - `st_filter` calls `dplyr::filter` on the data +#' +#' @examples +#' tab <- pt_data_inventory(pmt_obs, by = "FORM") +#' obj <- st_new(tab) +#' st_filter(obj, FORM != "troche") +#' st_select(obj, -contains("BQL")) +#' st_mutate(obj, FORM = ifelse(FORM=="tablet", "ODT", FORM)) #' #' @export st_select <- function(x, ...) { @@ -885,6 +899,16 @@ st_mutate <- function(x, ...) { x } +dplyr_filter <- dplyr::filter + +#' @rdname st_select +#' @export +st_filter <- function(x, ...) { + check_st(x) + x$data <- dplyr_filter(x$data, ...) + x +} + #' Edit table contents #' #' These functions modify the input data frame prior to passing to [stable()] diff --git a/inst/validation/pmtables-stories.yaml b/inst/validation/pmtables-stories.yaml index 2740ee42..d920ff83 100644 --- a/inst/validation/pmtables-stories.yaml +++ b/inst/validation/pmtables-stories.yaml @@ -1,4 +1,11 @@ # Please add user stories at the top of this file +PMT-S082: + name: Filter data from an st object + description: > + As a user, I want to filter data in an st object. + ProductRisk: low-risk + tests: + - PMT-STFUN-0001 PMT-S081: name: Customize All Data summary in pt inventory table description: > diff --git a/man/st_select.Rd b/man/st_select.Rd index b6d1ce3b..7074f6d2 100644 --- a/man/st_select.Rd +++ b/man/st_select.Rd @@ -3,18 +3,37 @@ \name{st_select} \alias{st_select} \alias{st_mutate} +\alias{st_filter} \title{Filter, select, or mutate data} \usage{ st_select(x, ...) st_mutate(x, ...) + +st_filter(x, ...) } \arguments{ -\item{x}{an stobject} +\item{x}{an stobject.} -\item{...}{passed to \code{\link[dplyr:select]{dplyr::select()}}, or \code{\link[dplyr:mutate]{dplyr::mutate()}}} +\item{...}{passed to \code{\link[dplyr:select]{dplyr::select()}}, \code{\link[dplyr:mutate]{dplyr::mutate()}}, or +\code{\link[dplyr:filter]{dplyr::filter()}}.} } \description{ These functions modify the input data frame prior to passing it to \code{\link[=stable]{stable()}} or \code{\link[=stable_long]{stable_long()}}. } +\details{ +\itemize{ +\item \code{st_select} calls \code{dplyr::select} on the data +\item \code{st_mutate} calls \code{dplyr::mutate} on the data +\item \code{st_filter} calls \code{dplyr::filter} on the data +} +} +\examples{ +tab <- pt_data_inventory(pmt_obs, by = "FORM") +obj <- st_new(tab) +st_filter(obj, FORM != "troche") +st_select(obj, -contains("BQL")) +st_mutate(obj, FORM = ifelse(FORM=="tablet", "ODT", FORM)) + +} diff --git a/tests/testthat/test-table-object.R b/tests/testthat/test-table-object.R index f6468437..7a987da3 100644 --- a/tests/testthat/test-table-object.R +++ b/tests/testthat/test-table-object.R @@ -412,3 +412,11 @@ test_that("substitute lines in table notes", { regexp = "did not find any notes" ) }) + +test_that("st_filter filters data in pmtable object [PMT-STFUN-0001]", { + data <- stdata() + x <- st_new(data) + y <- st_filter(x, FORM != "troche") + expect_true(all(y$data$FORM %in% c("tablet", "capsule"))) + expect_true("troche" %in% data$FORM) +}) From 5d5e8d9b840ea4835f4cb6c62cc0ebc907082a88 Mon Sep 17 00:00:00 2001 From: Kyle Baron Date: Wed, 10 Aug 2022 09:19:12 -0400 Subject: [PATCH 12/17] just use filter() --- R/table-object.R | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/R/table-object.R b/R/table-object.R index 2b3483f5..842c25dd 100644 --- a/R/table-object.R +++ b/R/table-object.R @@ -872,7 +872,6 @@ st_drop <- function(x, ...) { #' [dplyr::filter()]. #' #' @details -#' #' - `st_select` calls `dplyr::select` on the data #' - `st_mutate` calls `dplyr::mutate` on the data #' - `st_filter` calls `dplyr::filter` on the data @@ -899,13 +898,11 @@ st_mutate <- function(x, ...) { x } -dplyr_filter <- dplyr::filter - #' @rdname st_select #' @export st_filter <- function(x, ...) { check_st(x) - x$data <- dplyr_filter(x$data, ...) + x$data <- filter(x$data, ...) x } From d1f5d9ff50b936ecc3f5b4536f3f100ba0adce9a Mon Sep 17 00:00:00 2001 From: Kyle Baron Date: Tue, 16 Aug 2022 15:43:35 -0500 Subject: [PATCH 13/17] bump development version --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index cd8e0872..4e18345d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: pmtables Type: Package Title: Tables for Pharmacometrics -Version: 0.5.0.9000 +Version: 0.5.0.9001 Authors@R: c( person(given = "Kyle", From 800cafefee3b4fe7b802c9c9170f928117ab330a Mon Sep 17 00:00:00 2001 From: Kyle Baron Date: Tue, 16 Aug 2022 15:52:30 -0500 Subject: [PATCH 14/17] update news --- NEWS.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/NEWS.md b/NEWS.md index 7407bdfb..897a4f58 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,17 @@ # pmtables (development version) +- New function `st_filter()` to filter data item in a pipeline #298. + +- Add `summarize_all` and `all_name_stacked` arguments to + `pt_data_inventory()` #297. + +## Bugs Fixed + +- Fixed bug where `all_name` was not getting used in `pt_data_inventory()` #297. + +- Fixed bug where detached table notes were getting rendered too close to the + main table when building standalone pdf under certain TeX distributions #286. + # pmtables 0.5.0 - New functions `st_as_image()`, `st2pdf()`, and `st2png()` to render tables with From c6dc984936b9cb02a1d4f634599d0bc8532631cd Mon Sep 17 00:00:00 2001 From: Kyle Baron Date: Tue, 16 Aug 2022 15:54:12 -0500 Subject: [PATCH 15/17] tweak news --- NEWS.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/NEWS.md b/NEWS.md index 897a4f58..77b8c2ad 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,16 +1,18 @@ # pmtables (development version) -- New function `st_filter()` to filter data item in a pipeline #298. +- New function `st_filter()` to filter data item in a pipeline (#298). - Add `summarize_all` and `all_name_stacked` arguments to - `pt_data_inventory()` #297. + `pt_data_inventory()` (#297). ## Bugs Fixed -- Fixed bug where `all_name` was not getting used in `pt_data_inventory()` #297. +- Fixed bug where `all_name` was not getting used in `pt_data_inventory()` + (#297). - Fixed bug where detached table notes were getting rendered too close to the - main table when building standalone pdf under certain TeX distributions #286. + main table when building standalone pdf under certain TeX distributions + (#286). # pmtables 0.5.0 From 49a1b28b3b969f1413e5137d3e32f246674e2863 Mon Sep 17 00:00:00 2001 From: Kyle Baron Date: Tue, 16 Aug 2022 15:55:12 -0500 Subject: [PATCH 16/17] release version --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 4e18345d..a6875fc9 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: pmtables Type: Package Title: Tables for Pharmacometrics -Version: 0.5.0.9001 +Version: 0.5.0.9100 Authors@R: c( person(given = "Kyle", From 447e89b8c7cb41c11d01bee954788a62fe9f1da1 Mon Sep 17 00:00:00 2001 From: Kyle Baron Date: Fri, 19 Aug 2022 09:31:58 -0500 Subject: [PATCH 17/17] bump version --- DESCRIPTION | 2 +- NEWS.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index a6875fc9..f6f70177 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: pmtables Type: Package Title: Tables for Pharmacometrics -Version: 0.5.0.9100 +Version: 0.5.1 Authors@R: c( person(given = "Kyle", diff --git a/NEWS.md b/NEWS.md index 77b8c2ad..a1be2c87 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -# pmtables (development version) +# pmtables 0.5.1 - New function `st_filter()` to filter data item in a pipeline (#298).