Skip to content

Commit

Permalink
add total episodes to profile and documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
LylChun committed Jan 23, 2024
1 parent 7c28f72 commit 5f9a485
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
13 changes: 11 additions & 2 deletions R/epicalc_profile.R
Expand Up @@ -102,14 +102,23 @@ epicalc_profile <- function(data,lv1_hypo=70,lv2_hypo=54,lv1_hyper=180,lv2_hyper
tableStat[6, 7] = paste0(as.character(format(round(ep_summary$avg_ep_gl[6], 2), nsmall = 2)), " mg/dl")
tableStat[6, 8] = paste0(as.character(format(round(ep_summary$avg_ep_gl[7], 2), nsmall = 2)), " mg/dl")

tableStat[7, 1] = "Total episodes"
tableStat[7, 2] = paste0(as.character(format(round(ep_summary$total_episodes[1], 2), nsmall = 2)))
tableStat[7, 3] = paste0(as.character(format(round(ep_summary$total_episodes[2], 2), nsmall = 2)))
tableStat[7, 4] = paste0(as.character(format(round(ep_summary$total_episodes[3], 2), nsmall = 2)))
tableStat[7, 5] = paste0(as.character(format(round(ep_summary$total_episodes[4], 2), nsmall = 2)))
tableStat[7, 6] = paste0(as.character(format(round(ep_summary$total_episodes[5], 2), nsmall = 2)))
tableStat[7, 7] = paste0(as.character(format(round(ep_summary$total_episodes[6], 2), nsmall = 2)))
tableStat[7, 8] = paste0(as.character(format(round(ep_summary$total_episodes[7], 2), nsmall = 2)))

#Styling the table
mytheme <- gridExtra::ttheme_minimal(base_size = 10, padding = unit(c(4,2),"mm"))
t1 <- gridExtra::tableGrob(tableStat, rows = NULL, cols = NULL, theme = mytheme )

#Adding border(t1)
t1 <- gtable::gtable_add_grob(t1,
grobs = grid::rectGrob(gp = grid::gpar(fill = NA, lwd = 5)),
t = 1, b = 6, l = 1, r = 8)
t = 1, b = 7, l = 1, r = 8)
#Adding dotted separator(t1)
separators <- replicate(ncol(t1) - 2,
grid::segmentsGrob(x1 = unit(0, "npc"), gp=grid::gpar(lty=2)),
Expand All @@ -120,7 +129,7 @@ epicalc_profile <- function(data,lv1_hypo=70,lv2_hypo=54,lv1_hyper=180,lv2_hyper
padding <- unit(0.5,"line")

#Adding title and footnote(t1)
title <- grid::textGrob("Episode Metrics",gp=grid::gpar(fontsize=18), x=0, hjust=0)
title <- grid::textGrob(paste0("Episode Metrics - ", data$id[1]),gp=grid::gpar(fontsize=18), x=0, hjust=0)
footnote <- grid::textGrob(paste0("An episode is >= ", dur_length, " continuous minutes"), x=1, hjust=1,
gp=grid::gpar( fontface="italic", fontsize = 8))

Expand Down
1 change: 1 addition & 0 deletions R/episode_calculation.R
Expand Up @@ -253,6 +253,7 @@ episode_single = function(data, lv1_hypo, lv2_hypo, lv1_hyper, lv2_hyper,
#' (total # episodes)/(recording time in days (24hrs))}
#' \item{avg_ep_duration}{Average duration of episodes in minutes}
#' \item{avg_ep_gl}{Average glucose in the episode in mg/dL}
#' \item{total_episodes}{Total number of episodes in the subject's glucose trace}
#'
#' If return_data is TRUE, returns a list where the first entry is the episode summary dataframe
#' (see above) and the second entry is the input data with episode labels added. Note
Expand Down
1 change: 1 addition & 0 deletions man/episode_calculation.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5f9a485

Please sign in to comment.