@@ -63,59 +63,32 @@ summary.epi_df = function(object, ...) {
6363 dplyr :: summarize(mean(.data $ num )))))
6464}
6565
66- # ' @export
6766`[.epi_df` <- function (x , i , j , drop = FALSE ) {
6867 res <- NextMethod()
6968
7069 if (! is.data.frame(res )) return (res )
7170
72- i_arg <- substitute(i )
73- j_arg <- substitute(j )
74-
7571 if (missing(i )) {
7672 i <- NULL
7773 i_arg <- NULL
78- } else if (is.null(i )) {
79- i <- integer()
80- }
74+ }
8175
8276 if (missing(j )) {
8377 j <- NULL
8478 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+ }
9980
10081 cn <- names(res )
10182 nr <- vctrs :: vec_size(x )
10283 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 ))
10584
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 ))
10986
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" ))
11789}
11890
91+
11992# ' `dplyr` verbs
12093# '
12194# ' `dplyr` verbs for `epi_df` objects, preserving class and attributes.
0 commit comments