From 5f9a485e758520d45247c346df921379787f6ea2 Mon Sep 17 00:00:00 2001 From: L Chun <7ylchun@gmail.com> Date: Tue, 23 Jan 2024 11:41:17 -0600 Subject: [PATCH] add total episodes to profile and documentation --- R/epicalc_profile.R | 13 +++++++++++-- R/episode_calculation.R | 1 + man/episode_calculation.Rd | 1 + 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/R/epicalc_profile.R b/R/epicalc_profile.R index 8d4a179c..4dc79b35 100644 --- a/R/epicalc_profile.R +++ b/R/epicalc_profile.R @@ -102,6 +102,15 @@ 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 ) @@ -109,7 +118,7 @@ epicalc_profile <- function(data,lv1_hypo=70,lv2_hypo=54,lv1_hyper=180,lv2_hyper #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)), @@ -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)) diff --git a/R/episode_calculation.R b/R/episode_calculation.R index 83038f69..68a2b9a1 100644 --- a/R/episode_calculation.R +++ b/R/episode_calculation.R @@ -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 diff --git a/man/episode_calculation.Rd b/man/episode_calculation.Rd index cd6ee15f..c939683d 100644 --- a/man/episode_calculation.Rd +++ b/man/episode_calculation.Rd @@ -55,6 +55,7 @@ If return_data is FALSE, a single dataframe with columns: (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