This repository has been archived by the owner on May 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathdplyr.R
146 lines (130 loc) · 2.91 KB
/
dplyr.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
## Preserve attributes through dplyr operations
## attributes set by bomrang which should be preserved
# nocov start
.bomrang_attribs <- c(
"class",
"station",
"type",
"origin",
"location",
"lat",
"lon",
"start",
"end",
"count",
"units",
"years",
"ncc_list",
"vars",
"indices",
"groups"
)
#' @name filter
#' @rdname filter
#' @export
dplyr::filter
#' @name filter
#' @rdname filter
#' @keywords internal
#' @importFrom dplyr filter
#' @export
filter.bomrang_tbl <- function(.data, ...) {
attribs <- attributes(.data)[.bomrang_attribs]
.data <- NextMethod()
attributes(.data) <- utils::modifyList(attributes(.data), attribs)
.data
}
#' @name select
#' @rdname select
#' @export
dplyr::select
#' @name select
#' @rdname select
#' @keywords internal
#' @importFrom dplyr select
#' @export
select.bomrang_tbl <- function(.data, ...) {
attribs <- attributes(.data)[.bomrang_attribs]
.data <- NextMethod(.data)
attributes(.data) <- utils::modifyList(attributes(.data), attribs)
.data
}
#' @name mutate
#' @rdname mutate
#' @export
dplyr::mutate
#' @name mutate
#' @rdname mutate
#' @keywords internal
#' @importFrom dplyr mutate
#' @export
mutate.bomrang_tbl <- function(.data, ...) {
attribs <- attributes(.data)[.bomrang_attribs]
.data <- NextMethod(.data)
attributes(.data) <- utils::modifyList(attributes(.data), attribs)
.data
}
#' @name rename
#' @rdname rename
#' @export
dplyr::rename
#' @name rename
#' @rdname rename
#' @keywords internal
#' @importFrom dplyr rename
#' @export
rename.bomrang_tbl <- function(.data, ...) {
attribs <- attributes(.data)[.bomrang_attribs]
.data <- NextMethod(.data)
attributes(.data) <- utils::modifyList(attributes(.data), attribs)
.data
}
#' @name arrange
#' @rdname arrange
#' @export
dplyr::arrange
#' @name arrange
#' @rdname arrange
#' @keywords internal
#' @importFrom dplyr arrange
#' @export
arrange.bomrang_tbl <- function(.data, ...) {
attribs <- attributes(.data)[.bomrang_attribs]
.data <- NextMethod(.data)
attributes(.data) <- utils::modifyList(attributes(.data), attribs)
.data
}
#' @name group_by
#' @rdname group_by
#' @export
dplyr::group_by
#' @name group_by
#' @rdname group_by
#' @keywords internal
#' @importFrom dplyr group_by
#' @export
group_by.bomrang_tbl <- function(.data, ...) {
attribs <- attributes(.data)[setdiff(.bomrang_attribs, "class")]
.data <- NextMethod(.data)
attributes(.data) <- utils::modifyList(attributes(.data), attribs)
attr(.data, "class") <-
union(c("bomrang_tbl", "data.table", "grouped_df"),
attr(.data, "class"))
.data
}
#' @name slice
#' @rdname slice
#' @export
dplyr::slice
#' @name slice
#' @rdname slice
#' @keywords internal
#' @importFrom dplyr slice
#' @export
slice.bomrang_tbl <- function(.data, ...) {
attribs <- attributes(.data)[.bomrang_attribs]
.data <- NextMethod(.data)
attributes(.data) <- utils::modifyList(attributes(.data), attribs)
.data
}
# nocov end