1

When using xtable() to print a data frame into HTML email body the output changes to numeric instead of the original format on the data frame which is set as.hms()

The original observation is numeric: 79 and the below code converts the average to as.hms() format 00:01:19

Avg_Answer_Time <- transport %>%
  filter(Call_Type == "Inbound customer") %>% 
  summarise(as.hms(round(mean(TimeInQueue))))

And then run the below code for the data frame to HTML the output goes back to numeric on the email: 79

InboundSummary <- print(xtable(Inbound_Summary, digits = 0), type="html", print.results=FALSE, )
InboundBody <- paste0("<html>", InboundSummary, "</html>")

Is there any way to print as the original format (00:01:19) or have it to print the output as time format preferably minutes and seconds?


Example:

library(xtable)
library(hms)

seconds <- c(79,50,37)   
queue_secs <- as_hms(round(mean(seconds)))  
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>")
user20650
  • 24,654
  • 5
  • 56
  • 91
zealofshah
  • 11
  • 2
  • Please provide a Minimal reproducible example. See here: – TarJae Feb 25 '21 at 12:06
  • Reproducible example: `seconds <- c(79,50,37) 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("", time_in_secs,"")` – zealofshah Feb 25 '21 at 12:40
  • I don't think it is anything to do with html but is `xtable` formatting -- you see the issue with `xtable(x)`. An easy fix is to convert to character: `x$queue_secs <- as.character(x$queue_secs); xtable(x)` – user20650 Feb 25 '21 at 14:13

0 Answers0