Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reffn_at_path<- for postprocessing #219

Closed
gmbecker opened this issue Jul 20, 2021 · 5 comments
Closed

reffn_at_path<- for postprocessing #219

gmbecker opened this issue Jul 20, 2021 · 5 comments

Comments

@gmbecker
Copy link
Collaborator

as discussed with @anajens

@gmbecker
Copy link
Collaborator Author

@anajens I've added the fnotes_at_path<- function which allows for row and cell referntial footnotes to be added to an existing table. If we construct a table without any referential footnotes

race_levels <- c("WHITE",
                     "BLACK OR AFRICAN AMERICAN",
                     "ASIAN",
                     "AMERICAN INDIAN OR ALASKA NATIVE",
                     "MULTIPLE")
l1 <- basic_table() %>% split_cols_by("ARM") %>%
        split_rows_by("RACE", split_fun = keep_split_levels(race_levels)) %>%
        summarize_row_groups() %>%
        analyze("AGE", mean)


 tb1 <- build_table(l1, DM)
 tb1
                                      A: Drug X          B: Placebo       C: Combination 
-----------------------------------------------------------------------------------------
WHITE                                 14 (11.6%)         14 (13.2%)          18 (14%)    
  mean                             39.3571428571429   36.9285714285714   35.1111111111111
BLACK OR AFRICAN AMERICAN             28 (23.1%)         24 (22.6%)         27 (20.9%)   
  mean                             34.6785714285714   31.7083333333333          34       
ASIAN                                 79 (65.3%)         68 (64.2%)         84 (65.1%)   
  mean                             34.2025316455696   32.6764705882353   34.6309523809524
AMERICAN INDIAN OR ALASKA NATIVE        0 (0%)             0 (0%)             0 (0%)     
  mean                                    NA                 NA                 NA       
MULTIPLE                                0 (0%)             0 (0%)             0 (0%)     
  mean                                    NA                 NA                 NA       

We can then add them

fnotes_at_path(tb1, rowpath = c("RACE", "WHITE", "AGE", "mean"),
                   colpath = c("ARM", "B: Placebo")) <- "white arm b mean"

    fnotes_at_path(tb1, rowpath = c("RACE", "ASIAN", "@content", "ASIAN"),
                   colpath = c("ARM", "C: Combination")) <- "asian arm c content"

    fnotes_at_path(tb1, rowpath = c("RACE", "MULTIPLE", "@content", "MULTIPLE"),
                   colpath = NULL) <-  c("race multiple row fn 1", "race multiple row fn 2")
fnotes_at_path(tb1, rowpath = c("RACE", "WHITE", "AGE", "mean"),

tb1
                                      A: Drug X            B: Placebo         C: Combination 
---------------------------------------------------------------------------------------------
WHITE                                 14 (11.6%)           14 (13.2%)            18 (14%)    
  mean                             39.3571428571429   36.9285714285714 {1}   35.1111111111111
BLACK OR AFRICAN AMERICAN             28 (23.1%)           24 (22.6%)           27 (20.9%)   
  mean                             34.6785714285714     31.7083333333333            34       
ASIAN                                 79 (65.3%)           68 (64.2%)         84 (65.1%) {2} 
  mean                             34.2025316455696     32.6764705882353     34.6309523809524
AMERICAN INDIAN OR ALASKA NATIVE        0 (0%)               0 (0%)               0 (0%)     
  mean                                    NA                   NA                   NA       
MULTIPLE {3, 4}                         0 (0%)               0 (0%)               0 (0%)     
  mean                                    NA                   NA                   NA       
---------------------------------------------------------------------------------------------

{1} - white arm b mean
{2} - asian arm c content
{3} - race multiple row fn 1
{4} - race multiple row fn 2
`

@anajens
Copy link
Contributor

anajens commented Aug 12, 2021

Thanks so much @gmbecker, this looks great!

One question - does this also work for column footnotes? I tried the code below but I'm getting an error:

> fnotes_at_path(tb1, rowpath = NULL, colpath = c("ARM", "C: Combination")) <-  c("test col footer")
Error in (function (classes, fdef, mtable)  : 
  unable to find an inherited method for function ‘fnotes_at_path<-’ for signature ‘"TableTree", "NULL"’

I'm trying to make a table that looks like this:

                                      A: Drug X            B: Placebo         C: Combination {1}
---------------------------------------------------------------------------------------------
WHITE                                 14 (11.6%)           14 (13.2%)            18 (14%)    
...
---------------------------------------------------------------------------------------------

{1} - test col footer


@gmbecker
Copy link
Collaborator Author

gmbecker commented Aug 12, 2021 via email

@anajens
Copy link
Contributor

anajens commented Aug 12, 2021

According to the docs, rowpath does take NULL. I guess it's just a placeholder for now?

https://github.com/Roche/rtables/blob/78f8c7a3b89b74f55e0db38deb67b576a9a2192f/R/tree_accessors.R#L2265

@gmbecker
Copy link
Collaborator Author

gmbecker commented Aug 12, 2021 via email

gmbecker added a commit that referenced this issue Aug 27, 2021
* Exp allow a/cfuns + splfuns to accept .prev_splvals arg. #203 dev vbump

* Fix bug where names weren't showing up for .prev_splvals. #203 dev vbump

* Fix off-by-one error in pagination, sep in txt export.  Fixes #213

* add experimental fnotes_at_path function. Needs tests. #219. vbump

* Exp allow a/cfuns + splfuns to accept .prev_splvals arg. #203 dev vbump

* Fix bug where names weren't showing up for .prev_splvals. #203 dev vbump

* Fix off-by-one error in pagination, sep in txt export.  Fixes #213

* add experimental fnotes_at_path function. Needs tests. #219. vbump

* Run GH actions for all branches

* Working fntes_at_path with tests. Closes #219. dev vbump

* col ref footnote support. related to #219. Closes #187. dev vbump

* Support and tests for trim_levels_to_map. closes #203. Devel vbump.

* cell_values and value_at methods for Row objects. closes #210. dev vbump

* Trim outer levels to trim_levels_in_groups by deflt. #236 dev vbump

* Cleanup, additional tests, and fix bugs uncovered by new tests.

* Add NEWS entries, prepare for merge into main

Co-authored-by: dinakar29 <26552821+dinakar29@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants