@@ -99,17 +99,39 @@ createTaxonTable <- function(dat, n=10){
9999# ' createStudyTable(full.dat)
100100# ' ## kable_styling(kbl(createStudyTable(full.dat))) #for html styling
101101
102- createStudyTable <- function (dat ){
103- studies <- data.frame (Study = paste0(str_extract(dat $ Authors , " [A-Za-z]+[:space:]" ), dat $ Year ),
104- Condition = dat $ Condition ,
105- Cases = dat $ `Group 1 sample size` ,
106- Controls = dat $ `Group 0 sample size` ,
107- `Study Design` = dat $ `Study design` )
108- studies %> % group_by(Study ) %> % summarize(Condition = first(Condition ),
109- Cases = max(Cases ),
110- Controls = max(Controls ),
111- `Study Design` = first(`Study.Design` ))
102+ createStudyTable <- function (bsdb.df , includeAlso = NULL ) {
103+ # input check
104+ if (! is_null(includeAlso )) {
105+ if (! all(includeAlso %in% colnames(bsdb.df ))) {
106+ stop(paste(
107+ " The following columns are not found in the input data frame:" ,
108+ paste(includeAlso [! (includeAlso %in% colnames(bsdb.df ))], collapse = " , " )
109+ ))
110+ }
111+ }
112+ # Core of the change is in how study IDs are generated, see function in
113+ # simple.R. NB: the function also fixes DOI links as side effect, now.
114+
115+ bsdb_with_StudyCodes.df <- .make_unique_study_ID(bsdb.df )
116+
117+ # some dplyr-fu to summarize tables, with more recent syntax
118+ study_table_fixed <- bsdb_with_StudyCodes.df %> %
119+ group_by(`Study code` ) %> %
120+ reframe(
121+ MaxCases = max(`Group 1 sample size` ),
122+ MaxControls = max(`Group 0 sample size` ),
123+ across(
124+ all_of(
125+ c(" Study design" , " Condition" , " PMID" , " DOI" , " URL" , includeAlso )
126+ ),
127+ .fns = function (x )
128+ paste(unique(x ), collapse = " ; " )
129+ ),
130+ N_signatures = n()
131+ ) %> %
132+ relocate(N_signatures , .after = Condition )
112133
134+ return (study_table_fixed )
113135}
114136
115137globalVariables(
0 commit comments