Every R problem can be thought of with advantage as the interaction of three objects— an existing object, x , a desired object,y , and a function, f, that will return a value of y given x as an argument. In other words, school algebra— f(x) = y. Any of the objects can be composites.
In the problem x is typeof integer and y is typeof character. The most direct route from x \rightarrow y is directly through typeof character, rather than taking a detour to typeof datetime
suppressPackageStartupMessages({
library(stringr)
})
# Functions
get_hours <- function(x) ifelse (floor(x/3600 + x%%3600) == x,"0", as.character(floor(x/Hours)))
get_minutes <- function(x) ifelse (floor(x/60 + x%%60) == x,"0", as.character(floor(x/60)))
get_seconds <- function(x) x%%60
get_time_string <- function(x) str_glue(str_pad(get_hours(x),2,"left","0"),str_pad(get_minutes(x),2,"left","0"),str_pad(get_seconds(x),2,"left","0"),.sep = ":")
make_html <- function(x) str_glue("<html>",get_time_string(x),"</html")
# Data, a numeric vector
seconds <- c(92,100,45)
# Preprocessing to convert to numeric scalar
queue_secs <- round(mean(seconds))
# Main: make hms character string
make_html(queue_secs)
#> <html>00:01:19</html