@@ -16,47 +16,35 @@ create_organizer_table <- function(table.path = file.path("..", "data", "organiz
1616 mutate(order = ifelse(is.na(order ) | order == " " , Inf , as.numeric(order )))
1717
1818 # Add organizer group
19- groups <- c(" Local" , " Community" )
20- organizers [[" group" ]] <- ifelse(organizers [[" local" ]], groups [[1L ]], groups [[2L ]])
21-
22- # Loop over local and community
23- for (grp in groups ) {
24- cat(" ##" , grp , " \n\n " )
25-
26- df <- organizers | >
27- filter(group == grp ) | >
28- arrange(order , name ) | >
29- mutate(
30- img = sprintf(" {height=150}" , img_path ),
31- label = name
32- )
33-
34- # Fill empty slots so table is rectangular
35- n_missing <- ncol - (nrow(df ) %% ncol )
36- if (n_missing < ncol ) {
37- df <- bind_rows(df , data.frame (
38- name = rep(" " , n_missing ),
39- local = rep(FALSE , n_missing ),
40- order = rep(Inf , n_missing ),
41- img_path = rep(" " , n_missing ),
42- group = rep(grp , n_missing ),
43- img = rep(" " , n_missing ),
44- label = rep(" " , n_missing )
45- ))
46- }
47-
48- # Make matrix with alternating rows (image row, name row)
49- img_mtx <- matrix (df $ img , ncol = ncol , byrow = TRUE )
50- name_mtx <- matrix (df $ label , ncol = ncol , byrow = TRUE )
51- ij <- rep(seq_len(nrow(img_mtx )), each = 2 ) + c(0 , nrow(img_mtx ))
19+ df <- organizers | >
20+ arrange(order , name ) | >
21+ mutate(
22+ img = sprintf(" {height=150}" , img_path ),
23+ label = name
24+ )
25+ n_missing <- ncol - (nrow(df ) %% ncol )
26+ if (n_missing < ncol ) {
27+ df <- bind_rows(df , data.frame (
28+ name = rep(" " , n_missing ),
29+ local = rep(FALSE , n_missing ),
30+ order = rep(Inf , n_missing ),
31+ img_path = rep(" " , n_missing ),
32+ img = rep(" " , n_missing ),
33+ label = rep(" " , n_missing ),
34+ stringsAsFactors = FALSE
35+ ))
36+ }
37+ # Make matrix with alternating rows (image row, name row)
38+ img_mtx <- matrix (df $ img , ncol = ncol , byrow = TRUE )
39+ name_mtx <- matrix (df $ label , ncol = ncol , byrow = TRUE )
40+ ij <- rep(seq_len(nrow(img_mtx )), each = 2 ) + c(0 , nrow(img_mtx ))
5241
53- tbl <- data.frame (rbind(img_mtx , name_mtx )[ij , ])
42+ tbl <- data.frame (rbind(img_mtx , name_mtx )[ij , ])
5443
55- kable(tbl , format = " html" , align = align , col.names = NULL , escape = FALSE ,
56- table.attr = ' class="organizers-table table table-borderless"' ) | >
57- kable_styling(full_width = FALSE , position = " left" ) | >
58- print()
44+ kable(tbl , format = " html" , align = align , col.names = NULL , escape = FALSE ,
45+ table.attr = ' class="organizers-table table table-borderless"' ) | >
46+ kable_styling(full_width = FALSE , position = " left" ) | >
47+ print()
5948
60- cat(" \n\n " )
61- }
49+ cat(" \n\n " )
6250}
0 commit comments