-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgroup_by.R
98 lines (78 loc) · 2 KB
/
group_by.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#' @export
group_by.gen_tbl <- function(.data, ..., .add = FALSE, .drop = group_by_drop_default(.data)) {
out <- NextMethod()
class(out) <- c("grouped_gen_tbl", "grouped_df", "gen_tbl", class(out)[-1])
return(out)
}
#' @export
ungroup.grouped_gen_tbl <- function(x, ...) {
out <- NextMethod(...)
class(out) <- c("gen_tbl", class(out))
return(out)
}
#' @export
dplyr_reconstruct.gen_tbl <-function(data, template)
{
out <- NextMethod()
# if the genotypes are gone, drop the tbl_df class
if (!"genotypes" %in% names(data)){
message("as genotypes were dropped, this is not longer a 'gen_tbl'")
class(out) <- class(out)[-1]
}
out
}
#' @export
dplyr_reconstruct.grouped_gen_tbl <-function(data, template)
{
out <- NextMethod()
# if the genotypes are gone, drop the tbl_df class
if (!"genotypes" %in% names(data)){
message("as genotypes were dropped, this is not longer a 'gen_tbl'")
class(out) <- c("grouped_df", "tbl_df", "tbl", "data.frame")
}
out
}
# drop the `gen_tbl` class if the `genotype` column is subsetted out
#' @export
"[.gen_tbl" = function(x,i,j, ...){
x <- NextMethod()
if (!"genotypes" %in% names(x)){
class(x)<-class(x)[!class(x)%in% "gen_tbl"]
}
x
}
# drop the `gen_tbl` class if the `genotype` column is subsetted out
#' @export
"[.grouped_gen_tbl" = function(x,i,j, ...){
original_class <- class(x)
x <- NextMethod()
class(x) <- original_class
if (!"genotypes" %in% names(x)){
class(x)<-class(x)[!class(x)%in% c("grouped_gen_tbl","gen_tbl")]
}
x
}
#' @export
dplyr_row_slice.grouped_gen_tbl <- function(data, i, ...){
original_class <- class(data)
x <- NextMethod()
class(x) <- original_class
x
}
#' @export
dplyr_col_modify.grouped_gen_tbl <- function(data, cols){
original_class <- class(data)
x <- NextMethod()
class(x) <- original_class
x
}
# #' @export
# dplyr_row_slice.gen_tbl<-function(data, i, ...){
# NextMethod()
#
#}
# #' @export
# dplyr_col_modify.gen_tbl<-function(data, cols){
# NextMethod()
#
# }