@@ -63,59 +63,32 @@ summary.epi_df = function(object, ...) {
63
63
dplyr :: summarize(mean(.data $ num )))))
64
64
}
65
65
66
- # ' @export
67
66
`[.epi_df` <- function (x , i , j , drop = FALSE ) {
68
67
res <- NextMethod()
69
68
70
69
if (! is.data.frame(res )) return (res )
71
70
72
- i_arg <- substitute(i )
73
- j_arg <- substitute(j )
74
-
75
71
if (missing(i )) {
76
72
i <- NULL
77
73
i_arg <- NULL
78
- } else if (is.null(i )) {
79
- i <- integer()
80
- }
74
+ }
81
75
82
76
if (missing(j )) {
83
77
j <- NULL
84
78
j_arg <- NULL
85
- } else if (is.null(j )) {
86
- j <- integer()
87
- }
88
-
89
- # Ignore drop as an argument for counting
90
- n_real_args <- nargs() - ! missing(drop )
91
-
92
- # Case when the number of args (excluding drop) is not 3 or more
93
- if (n_real_args < = 2L ) {
94
- j <- i
95
- i <- NULL
96
- j_arg <- i_arg
97
- i_arg <- NULL
98
- }
79
+ }
99
80
100
81
cn <- names(res )
101
82
nr <- vctrs :: vec_size(x )
102
83
not_epi_df <- (! (" time_value" %in% cn ) || ! (" geo_value" %in% cn ) || vctrs :: vec_size(res ) > nr || any(i > nr ))
103
-
104
- if (not_epi_df ) return (tibble :: as_tibble(res ))
105
84
106
- # Case when i is numeric and there are duplicate values in it
107
- if (is.numeric(i ) && vctrs :: vec_duplicate_any(i ) > 0 )
108
- return (tibble :: as_tibble(res ))
85
+ if (not_epi_df ) return (tibble :: as_tibble(res ))
109
86
110
- att_x = attr(x , " metadata" )
111
- new_epi_df(tibble :: as_tibble(res ),
112
- geo_type = att_x $ geo_type ,
113
- time_type = att_x $ time_type ,
114
- as_of = att_x $ as_of ,
115
- additional_metadata =
116
- att_x [! (names(att_x ) %in% c(" geo_type" , " time_type" , " as_of" ))])
87
+ # Use reclass as safeguard (in case class & metadata are dropped)
88
+ reclass(res , attr(x , " metadata" ))
117
89
}
118
90
91
+
119
92
# ' `dplyr` verbs
120
93
# '
121
94
# ' `dplyr` verbs for `epi_df` objects, preserving class and attributes.
0 commit comments