Skip to content

Commit 9a6deee

Browse files
committed
Updates as per comments on Github
1 parent 5ec260b commit 9a6deee

File tree

1 file changed

+7
-16
lines changed

1 file changed

+7
-16
lines changed

R/methods-epi_df.R

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -71,45 +71,36 @@ summary.epi_df = function(object, ...) {
7171

7272
if (missing(i)) {
7373
i <- NULL
74-
i_arg <- NULL
7574
}
7675

7776
if (missing(j)) {
7877
j <- NULL
79-
j_arg <- NULL
8078
}
8179

8280
cn <- names(res)
8381

84-
# Duplicate columns, Abort
82+
# Duplicate key columns, Abort
8583
dup_col_names = cn[duplicated(cn)]
8684
if (length(dup_col_names) != 0) {
8785
Abort(paste0("Column name(s) ",
8886
paste(unique(dup_col_names),
8987
collapse = ", "), " must not be duplicated."))
9088
}
9189

92-
# If not an epi_df (missing time_value or geo_value), return a tibble
93-
not_epi_df <- (!("time_value" %in% cn) || !("geo_value" %in% cn))
90+
not_epi_df <- !("time_value" %in% cn) || !("geo_value" %in% cn)
9491

9592
if (not_epi_df) {
9693
attributes(res)$metadata <- NULL
9794
return(tibble::as_tibble(res))
9895
}
9996

10097
# Use reclass as safeguard (in case class &/or metadata are dropped)
101-
reclass(res, attr(x, "metadata"))
98+
res <- reclass(res, attr(x, "metadata"))
10299

103-
# Amend additional metadata if some other_keys cols are dropped
104-
105-
# Extract the other_keys colnames in the original epi_df that do not occur in the subset
106-
only_in_orig = setdiff(unlist(attr(x, "metadata")$other_keys),
107-
cn[!(cn %in% c("geo_value", "time_value"))])
108-
109-
if (length(only_in_orig) != 0) {
110-
# remove all other_keys elements in the original epi_df that do not occur in subset
111-
attr(res, "metadata")$other_keys =
112-
attr(res, "metadata")$other_keys[! attr(res, "metadata")$other_keys %in% only_in_orig]
100+
# Amend additional metadata if some other_keys cols are dropped in the subset
101+
old_other_keys = attr(x, "metadata")$other_keys
102+
if (length(setdiff(old_other_keys, cn)) > 0) {
103+
attr(res, "metadata")$other_keys <- intersect(old_other_keys, cn)
113104
}
114105

115106
res

0 commit comments

Comments
 (0)