mikeblazanin / gcplyr

gcplyr is an R package that facilitates wrangling and analysis of microbial growth curve data
https://mikeblazanin.github.io/gcplyr/
Other
29 stars 2 forks source link

Helper Function: format.time #123

Open discoleo opened 1 year ago

discoleo commented 1 year ago

Helper Function: format.time

The vignette Importing and Formatting Data starts with a lot of boiler-plate code, including: paste("Plate1-", paste(example_widedata_noiseless$Time %/% 3600, formatC((example_widedata_noiseless$Time %% 3600) %/% 60, width = 2, flag = 0), formatC((example_widedatanoiseless$Time %% 3600) %% 60, width = 2, flag = 0), sep = ""), ".csv", sep = "")

The time-formatting code could be moved to a helper function inside the package:

Note:

R Code

# separator for plots = ":";
format.time = function(x, sep=":", h.width=2) {
   h  = x %/% 3600;
   ms = x %%  3600;
   if(h.width != 1) h = formatC(h, width = h.width, flag = 0);
   paste(h,
      formatC(ms %/% 60, width = 2, flag = 0),
      formatC(ms %% 60, width = 2, flag = 0), sep=sep);
}
discoleo commented 1 year ago

Vignette Introduction to using gcplyr

The first image (on page 2) could also benefit from this function:

I have enhanced in the meanwhile the initial format.time function:

The latest code can be found on my GitHub page, see: https://github.com/discoleo/R/blob/master/Stat/Tools.DateTime.R

Naming of Functions

Important advantage of format.time over formatTime or format_time:

mikeblazanin commented 8 months ago

Since these time-formatting steps in the vignetted have been moved into make_example (#132), the utility of implementing this is now very limited