Print the time format (mm:ss) in HTML

I am attempting to convert a second in numeric value into time format when printing out in HTML outlook mail. My data frame displays 79 as 00:01:19 however when I use xtable() and print() the result spits out 79 instead of 00:01:19. I am using xtable() and RDCOMClien() and hms() packages.

A reproducible example is:

          seconds <- c(92,100,45)   
          queue_secs <- as.hms(round(mean(queue_secs)))   
          x <- data.frame(queue_secs) 
          time_in_secs <- print(xtable(x), type="html", print.results=FALSE, ) 
          time_in_secs_body <- paste0("<html>", time_in_secs,"<html>")```

Does anyone know what the magic is to have the time format as the output in HTML or any alternative suggestions?

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


# 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 

#> <html>00:01:19</html
1 Like

Thank you Sir! Not only did it work but it was a good refresher on school algebra :smile:

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.