-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreconstruct.R
67 lines (61 loc) · 1.41 KB
/
reconstruct.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
reconstruct.tbl_time <- function(new, old) {
# Check subclass
subclass <- NULL
if(inherits(new, "grouped_df")) {
subclass <- "grouped_tbl_time"
}
# If we have an index
if(index_still_exists(new, old)) {
new_tbl_time(
new,
index = get_index_quo(old),
index_time_zone = get_index_time_zone(old),
subclass = subclass
)
}
else {
tibble::new_tibble(new, subclass = subclass)
}
}
# reconstruct.grouped_tbl_time <- function(new, old) {
#
# has_index <- index_still_exists(new, old)
# has_groups <- dplyr::is.grouped_df(new)
# has_index_and_groups <- has_index & has_groups
#
# # Easy case, still grouped_tbl_time
# if(has_index_and_groups) {
# new_grouped_tbl_time(
# new,
# index = get_index_quo(old),
# index_time_zone = get_index_time_zone(old)
# )
# }
#
# # If it has index or group, but not both
# else if(has_index | has_groups) {
#
# # tbl_time
# if(has_index) {
# new_tbl_time(
# new,
# index_quo = get_index_quo(old),
# index_time_zone = get_index_time_zone(old)
# )
# }
#
# # grouped_df
# else if(has_groups) {
# dplyr::grouped_df(new, dplyr::group_vars(new))
# }
# }
#
# # No index, no groups
# else {
# as_tibble(new)
# }
#
# }
index_still_exists <- function(new, old) {
get_index_char(old) %in% colnames(new)
}