2
2
# ' @export
3
3
# ' @include annotation_source_class.R
4
4
combine_records <- function (group_by ,
5
- default_fcn = .collapse (separator = " || " ),
5
+ default_fcn = fuse (separator = " || " ),
6
6
fcns = list (),
7
7
... ) {
8
8
# check fcns are all functions
206
206
# ' and placed last if `ties = FALSE` (values are returned preferentially over
207
207
# ' NA).
208
208
# '
209
- .mode <- function (ties = FALSE , na.rm = TRUE ) {
209
+ compute_mode <- function (ties = FALSE , na.rm = TRUE ) {
210
210
fcn <- expr(function (x ) {
211
211
if (length(x ) < = 2 ) {
212
212
return (x [1 ])
232
232
# ' @export
233
233
# ' @describeIn combine_records_helper_functions calculates the mean value,
234
234
# ' excluding NA if `na.rm = TRUE`
235
- .mean <- function () {
235
+ compute_mean <- function (na.rm = TRUE ) {
236
236
fcn <- expr(function (x ) {
237
- mean(x , na.rm = TRUE )
237
+ mean(x , na.rm = !! na.rm )
238
238
})
239
239
return (eval(fcn ))
240
240
}
243
243
# ' @describeIn combine_records_helper_functions calculates the median value,
244
244
# ' excluding NA if `na.rm = TRUE`
245
245
# ' @export
246
- .median <- function () {
246
+ compute_median <- function (na.rm = TRUE ) {
247
247
fcn <- expr(function (x ) {
248
- stats :: median(x , na.rm = TRUE )
248
+ stats :: median(x , na.rm = !! na.rm )
249
249
})
250
250
return (eval(fcn ))
251
251
}
256
256
# ' @param separator (character) a string used to separate multiple matches.
257
257
# ' @param na_string (character) a string used to represent NA values.
258
258
# ' @export
259
- .collapse <- function (separator , na_string = " NA" ) {
259
+ fuse <- function (separator , na_string = " NA" ) {
260
260
fcn <- expr(function (x ) {
261
261
x [is.na(x )] <- !! na_string
262
262
paste0(x , collapse = !! separator )
272
272
# ' @param keep_NA (logical) If TRUE then records with NA are returned as well as
273
273
# ' the record with the maximum value.
274
274
# ' @export
275
- . select_max <- function (max_col , use_abs = FALSE , keep_NA = FALSE ) {
275
+ select_max <- function (max_col , use_abs = FALSE , keep_NA = FALSE ) {
276
276
fcn <- expr(function (x ) {
277
277
# get values
278
278
vals <- as.numeric(pick(!! max_col )[[1 ]])
311
311
# ' @param keep_NA (logical) If TRUE then records with NA are returned as well as
312
312
# ' the record with the minimum value.
313
313
# ' @export
314
- . select_min <- function (min_col , use_abs = FALSE , keep_NA = FALSE ) {
314
+ select_min <- function (min_col , use_abs = FALSE , keep_NA = FALSE ) {
315
315
fcn <- expr(function (x ) {
316
316
# get values
317
317
vals <- as.numeric(pick(!! min_col )[[1 ]])
@@ -342,13 +342,13 @@ NULL
342
342
# ' Select matching annotations
343
343
# ' @describeIn combine_records_helper_functions returns all records based on
344
344
# ' the indices of identical matches in a second column and collapses them
345
- # ' useing the provided separator.
345
+ # ' using the provided separator.
346
346
# ' @param match_col (character) the name of a column to search for matches to
347
347
# ' the search column.
348
348
# ' @param search_col (character) the name of a column to use as a reference for
349
349
# ' locating values in the matching column.
350
350
# ' @export
351
- . select_match <- function (match_col , search_col , separator , na_string = " NA" ) {
351
+ select_match <- function (match_col , search_col , separator , na_string = " NA" ) {
352
352
fcn <- expr(function (x ) {
353
353
x <- x [which(pick(!! search_col )[[1 ]] == pick(!! match_col )[[1 ]])]
354
354
if (! is.null(!! separator )) {
@@ -374,15 +374,15 @@ NULL
374
374
# ' # Select matching records
375
375
# ' M <- combine_records(
376
376
# ' group_by = "example",
377
- # ' default_fcn = . select_exact(
377
+ # ' default_fcn = select_exact(
378
378
# ' match_col = "match_column",
379
379
# ' match = "find_me",
380
380
# ' separator = ", ",
381
381
# ' na_string = "NA"
382
382
# ' )
383
383
# ' )
384
384
# ' @export
385
- . select_exact <- function (match_col , match , separator , na_string = " NA" ) {
385
+ select_exact <- function (match_col , match , separator , na_string = " NA" ) {
386
386
fcn <- expr(function (x ) {
387
387
x <- x [which(pick(!! match_col ) == !! match )]
388
388
@@ -411,15 +411,15 @@ NULL
411
411
# ' # Collapse unique values
412
412
# ' M <- combine_records(
413
413
# ' group_by = "example",
414
- # ' default_fcn = .unique (
414
+ # ' default_fcn = fuse_unique (
415
415
# ' digits = 6,
416
416
# ' separator = ", ",
417
417
# ' na_string = "NA",
418
418
# ' sort = FALSE
419
419
# ' )
420
420
# ' )
421
421
# ' @export
422
- .unique <- function (separator ,
422
+ fuse_unique <- function (separator ,
423
423
na_string = " NA" ,
424
424
digits = 6 ,
425
425
drop_na = FALSE ,
@@ -463,14 +463,14 @@ NULL
463
463
# ' # Prioritise by source
464
464
# ' M <- combine_records(
465
465
# ' group_by = "InChiKey",
466
- # ' default_fcn = . prioritise(
466
+ # ' default_fcn = prioritise(
467
467
# ' match_col = "source",
468
468
# ' priority = c("CD", "LS"),
469
469
# ' separator = " || "
470
470
# ' )
471
471
# ' )
472
472
# ' @export
473
- . prioritise <- function (match_col ,
473
+ prioritise <- function (match_col ,
474
474
priority ,
475
475
separator ,
476
476
no_match = NA ,
@@ -522,10 +522,10 @@ NULL
522
522
# ' # Do nothing to all columns
523
523
# ' M <- combine_records(
524
524
# ' group_by = "InChiKey",
525
- # ' default_fcn = . nothing()
525
+ # ' default_fcn = nothing()
526
526
# ' )
527
527
# ' @export
528
- . nothing <- function () {
528
+ nothing <- function () {
529
529
fcn <- expr(function (x ) {
530
530
return (x )
531
531
})
@@ -542,11 +542,11 @@ NULL
542
542
# ' M <- combine_records(
543
543
# ' group_by = "InChiKey",
544
544
# ' fcns = list(
545
- # ' count = .count ()
545
+ # ' count = count_records ()
546
546
# ' )
547
547
# ' )
548
548
# ' @export
549
- .count <- function () {
549
+ count_records <- function () {
550
550
fcn <- expr(function (x ) {
551
551
y <- pick(everything())
552
552
return (nrow(y ))
@@ -569,14 +569,14 @@ NULL
569
569
# ' # Select annotation with highest (best) grade
570
570
# ' M <- combine_records(
571
571
# ' group_by = "InChiKey",
572
- # ' default_fcn = . select_grade(
572
+ # ' default_fcn = select_grade(
573
573
# ' grade_col = "grade",
574
574
# ' keep_NA = FALSE,
575
575
# ' upper_case = TRUE
576
576
# ' )
577
577
# ' )
578
578
# ' @export
579
- . select_grade <- function (grade_col , keep_NA = FALSE , upper_case = TRUE ) {
579
+ select_grade <- function (grade_col , keep_NA = FALSE , upper_case = TRUE ) {
580
580
fcn <- expr(function (x ) {
581
581
# get values
582
582
vals <- pick(!! grade_col )
0 commit comments