makeAggregator: generate JSON to aggregate (counting records, and, by...

Description Usage Arguments Value Note Examples

View source: R/lite.R

Description

generate JSON to aggregate (counting records, and, by default, averaging a given variable) within a collection

Usage

1
2
3
4
5
6
makeAggregator(
  by = "chrom",
  vbl = "chromStart",
  opname = "average",
  op = "$avg"
)

Arguments

by

character(1) telling the field for stratifying records for aggregation

vbl

character(1) telling field with numerical value for which a statistic will be computed within strata defined by 'by'

opname

character(1) define the name of the aggregation

op

character(1) evaluating to a mongo aggregation operator like '$avg' or '$min'

Value

a JSON document as produced by rjson::toJSON

Note

This produces json that can be used as an argument to m$aggregate() for m a mongolite::mongo instance

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
makeAggregator()
if (interactive() & verifyHasMongoCmd()) {
   remURL = URL_txregLocal()
   colls = listAllCollections( url=remURL, db = 'txregnet')
   m1 = mongo(url = remURL, db = 'txregnet', 
     collection='CD14_DS17215_hg19_FP')
# find minimum value of statistic 'stat' per chromosome
   newagg = makeAggregator( by='chr',
     vbl='stat', op='$min', opname='min')
   tab = m1$aggregate( newagg )
   head(tab)
   }

vjcitn/TxRegInfra2 documentation built on Jan. 1, 2021, 12:41 p.m.