|
|
|
|
|
|
|
|
key_values <- key_values[!key_values %in% ids] |
|
|
key_values <- key_values[!key_values %in% ids] |
|
|
|
|
|
|
|
|
id_values <- x %>% select(one_of(ids)) |
|
|
id_values <- x %>% select(one_of(ids)) |
|
|
id_values <- id_values %>% gather(key = ".key_map", value = ".id_map") |
|
|
|
|
|
|
|
|
id_values <- id_values %>% tidyr::gather(key = ".key_map", value = ".id_map") |
|
|
|
|
|
|
|
|
x <- x %>% mutate(.r = row_number()) %>% |
|
|
x <- x %>% mutate(.r = row_number()) %>% |
|
|
unite(one_of(ids), col = ".id_map", remove = F) |
|
|
|
|
|
|
|
|
tidyr::unite(dplyr::one_of(ids), col = ".id_map", remove = F) |
|
|
|
|
|
|
|
|
x <- x %>% |
|
|
x <- x %>% |
|
|
gather(key = ".col", value = ".val", names(x)[grepl("^[^\\.]", names(x))]) %>% |
|
|
gather(key = ".col", value = ".val", names(x)[grepl("^[^\\.]", names(x))]) %>% |
|
|
|
|
|
|
|
|
tmp <- x %>% filter(.key_map %in% ids) |
|
|
tmp <- x %>% filter(.key_map %in% ids) |
|
|
x <- bind_rows( |
|
|
x <- bind_rows( |
|
|
left_join(tmp %>% select(-.key_map), |
|
|
left_join(tmp %>% select(-.key_map), |
|
|
tmp %>% select(.id_map) %>% crossing(.key_map = key_values), |
|
|
|
|
|
|
|
|
tmp %>% select(.id_map) %>% tidyr::crossing(.key_map = key_values), |
|
|
by = ".id_map"), |
|
|
by = ".id_map"), |
|
|
x %>% filter(!.key_map %in% ids) |
|
|
x %>% filter(!.key_map %in% ids) |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
# add header: |
|
|
# add header: |
|
|
crosser <- crossing(.id_map = as.character(id_values$.id_map), |
|
|
|
|
|
|
|
|
crosser <- tidyr::crossing(.id_map = as.character(id_values$.id_map), |
|
|
.key_map = key_values) |
|
|
.key_map = key_values) |
|
|
key_header <- data_frame( |
|
|
key_header <- data_frame( |
|
|
.key_map = key_values, |
|
|
.key_map = key_values, |
|
|
|
|
|
|
|
|
.x = 1:length(ids), |
|
|
.x = 1:length(ids), |
|
|
.y = 0, |
|
|
.y = 0, |
|
|
.header = TRUE), |
|
|
.header = TRUE), |
|
|
crossing(.id_map = ids, .key_map = key_values), |
|
|
|
|
|
|
|
|
tidyr::crossing(.id_map = ids, .key_map = key_values), |
|
|
by = ".id_map" |
|
|
by = ".id_map" |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
x <- bind_rows(id_header, key_header, x) |
|
|
x <- bind_rows(id_header, key_header, x) |
|
|
|
|
|
|
|
|
x <- x %>% unite(.key_map, .id_map, .val, col = ".id", remove = F) |
|
|
|
|
|
|
|
|
x <- x %>% tidyr::unite(.key_map, .id_map, .val, col = ".id", remove = F) |
|
|
|
|
|
|
|
|
x %>% |
|
|
x %>% |
|
|
add_color_tidyr(key_values = key_values) %>% |
|
|
add_color_tidyr(key_values = key_values) %>% |
|
|
|
|
|
|
|
|
xn <- names(x) |
|
|
xn <- names(x) |
|
|
|
|
|
|
|
|
x <- x %>% mutate(.r = row_number()) %>% |
|
|
x <- x %>% mutate(.r = row_number()) %>% |
|
|
unite(ids, col = ".id_map", remove = F) %>% |
|
|
|
|
|
unite(key, col = ".key_map", remove = F) |
|
|
|
|
|
|
|
|
tidyr::unite(ids, col = ".id_map", remove = F) %>% |
|
|
|
|
|
tidyr::unite(key, col = ".key_map", remove = F) |
|
|
|
|
|
|
|
|
key_values <- x %>% pull(key) %>% unique() |
|
|
key_values <- x %>% pull(key) %>% unique() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
names(x_dict) <- xn |
|
|
names(x_dict) <- xn |
|
|
|
|
|
|
|
|
x <- x %>% |
|
|
x <- x %>% |
|
|
gather(key = ".col", value = ".val", names(x)[grepl("^[^\\.]", names(x))]) %>% |
|
|
|
|
|
|
|
|
tidyr::gather(key = ".col", value = ".val", names(x)[grepl("^[^\\.]", names(x))]) %>% |
|
|
mutate( |
|
|
mutate( |
|
|
.x = x_dict[.col], |
|
|
.x = x_dict[.col], |
|
|
.y = -rep(1:nr, nc), |
|
|
.y = -rep(1:nr, nc), |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# add headers: |
|
|
# add headers: |
|
|
|
|
|
|
|
|
id_headers <- crossing(.id_map = ids, # x$.id_map %>% unique() |
|
|
|
|
|
.key_map = key_values, |
|
|
|
|
|
) %>% |
|
|
|
|
|
|
|
|
id_headers <- tidyr::crossing(.id_map = ids, # x$.id_map %>% unique() |
|
|
|
|
|
.key_map = key_values, |
|
|
|
|
|
) %>% |
|
|
mutate( |
|
|
mutate( |
|
|
.r = 0, |
|
|
.r = 0, |
|
|
.col = "id", |
|
|
.col = "id", |
|
|
|
|
|
|
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
x <- x %>% |
|
|
x <- x %>% |
|
|
add_row( |
|
|
|
|
|
|
|
|
dplyr::add_row( |
|
|
.before = T, |
|
|
.before = T, |
|
|
.id_map = c(rep("key", length(key)), rep("value", length(value))), |
|
|
.id_map = c(rep("key", length(key)), rep("value", length(value))), |
|
|
.key_map = c(rep("key", length(key)), rep("value", length(value))), |
|
|
.key_map = c(rep("key", length(key)), rep("value", length(value))), |
|
|
|
|
|
|
|
|
x <- bind_rows(id_headers, x) |
|
|
x <- bind_rows(id_headers, x) |
|
|
|
|
|
|
|
|
x <- x %>% |
|
|
x <- x %>% |
|
|
unite(.key_map, .id_map, .val, col = ".id", remove = F) |
|
|
|
|
|
|
|
|
tidyr::unite(.key_map, .id_map, .val, col = ".id", remove = F) |
|
|
|
|
|
|
|
|
x %>% add_color_tidyr(key_values = key_values) %>% |
|
|
x %>% add_color_tidyr(key_values = key_values) %>% |
|
|
mutate(.alpha = ifelse(.header == TRUE, 1, 0.6)) |
|
|
mutate(.alpha = ifelse(.header == TRUE, 1, 0.6)) |