33# ' @param dat data.frame produced by \link[bugsigdbr]{importBugSigDB}, subsetted as desired
44# ' @param n number of taxa to return (if sig.type=="both", this is the number of taxa to return for each direction)
55# '
6- # ' @importFrom dplyr filter %>% mutate rowwise n_distinct group_by relocate rename first ungroup across
6+ # ' @importFrom dplyr filter %>% mutate rowwise n_distinct group_by relocate rename first ungroup across n
77# ' @importFrom utils relist head
88# ' @importFrom stats quantile binom.test
99# ' @importFrom kableExtra kbl kable_styling
1010# ' @importFrom tidyr separate
1111# ' @importFrom stringr str_replace str_extract
12+ # ' @importFrom bugsigdbr getSignatures
13+ # '
1214# ' @return kable table with increased and decreased taxa and a binomial test based on total number of studies in the data.frame
1315# ' @export
1416# '
@@ -23,7 +25,7 @@ createTaxonTable <- function(dat, n=10){
2325 data.frame (getMostFrequentTaxa(dat , sig.type = " both" , n = n ),
2426 stringsAsFactors = FALSE ) %> %
2527 mutate(metaphlan_name = Var1 ) %> %
26- tidyr :: separate(
28+ separate(
2729 col = Var1 ,
2830 sep = " \\ |" ,
2931 into = dmap ,
@@ -48,7 +50,7 @@ createTaxonTable <- function(dat, n=10){
4850 .countTaxon(dat = dat , x = x , direction = " decreased" ))) %> %
4951 mutate(Taxon = gsub(" .+\\ |" , " " , output $ metaphlan_name ))
5052
51- output %> % tidyr :: separate(col = " Taxon" , into = c(" Taxonomic Level" , " Taxon Name" ), sep = " __" ) %> %
53+ output %> % separate(col = " Taxon" , into = c(" Taxonomic Level" , " Taxon Name" ), sep = " __" ) %> %
5254 mutate(`Taxonomic Level` = unname(dmap [`Taxonomic Level` ])) %> %
5355 rowwise() %> %
5456 mutate( `Binomial Test pval` = .createBinomTestSummary(increased_signatures , total_signatures , wordy = FALSE )) %> %
@@ -60,7 +62,7 @@ createTaxonTable <- function(dat, n=10){
6062 if (direction [1 ] %in% c(" increased" , " decreased" )){
6163 dat <- filter(dat , `Abundance in Group 1` == direction [1 ])
6264 }
63- allnames <- bugsigdbr :: getSignatures(dat , tax.id.type = " metaphlan" )
65+ allnames <- getSignatures(dat , tax.id.type = " metaphlan" )
6466 sum(vapply(allnames , function (onesignames ) x %in% onesignames , FUN.VALUE = 1L ))
6567}
6668
@@ -86,22 +88,23 @@ createTaxonTable <- function(dat, n=10){
8688
8789# ' Create a table of all studies currently in data.frame
8890# '
89- # ' @param dat data.frame produced by \link[bugsigdbr]{importBugSigDB}, subsetted as desired
91+ # ' @param bsdb.df \code{data.frame} produced by \link[bugsigdbr]{importBugSigDB}, pre-filtered as desired
92+ # ' @param includeAlso \code{character} with column names to additionally include in the output table (default = `NULL`)
9093# '
91- # ' @importFrom dplyr group_by summarize %>%
94+ # ' @importFrom dplyr group_by %>% select relocate reframe across n
95+ # ' @importFrom tidyr all_of
9296# ' @importFrom kableExtra kbl kable_styling
9397# ' @return a data.frame of basic study information. Can be wrapped in
94- # ' kable_styling(kbl(.)) to format nicely.
98+ # ' kable_styling(kbl(... )) to format nicely.
9599# ' @export
96100# '
97101# ' @examples
98102# ' full.dat <- bugsigdbr::importBugSigDB()
99103# ' createStudyTable(full.dat)
100- # ' ## kable_styling(kbl(createStudyTable(full.dat))) #for html styling
101104
102105createStudyTable <- function (bsdb.df , includeAlso = NULL ) {
103106 # input check
104- if (! is_null (includeAlso )) {
107+ if (! is.null (includeAlso )) {
105108 if (! all(includeAlso %in% colnames(bsdb.df ))) {
106109 stop(paste(
107110 " The following columns are not found in the input data frame:" ,
@@ -153,7 +156,18 @@ globalVariables(
153156 " Freq" ,
154157 " species" ,
155158 " kingdom" ,
156- " Var1"
159+ " Var1" ,
160+ # the following are necessary after the merged data
161+ " Authors" ,
162+ " Year" ,
163+ " BasicID" ,
164+ " PMID" ,
165+ " URL" ,
166+ " uniqueRank" ,
167+ " Study code" ,
168+ " Group 0 sample size" ,
169+ " Group 1 sample size" ,
170+ " N_signatures"
157171 )
158172)
159173
0 commit comments