a solution could be to put the databar
before using the xtable
function, like this :
d1 <- data.frame(x1 = c("A", "B", "C", "D", "E", "F"), x2 = runif(6)*100)
d1
# x1 x2
# 1 A 0.2890781
# 2 B 99.9268717
# 3 C 70.0964751
# 4 D 90.7419767
# 5 E 58.6721176
# 6 F 38.5582817
d1$x3 <- paste0("\\databar{", round(d1$x2, 2), "}")
d1
# x1 x2 x3
# 1 A 0.2890781 \\databar{0.29}
# 2 B 99.9268717 \\databar{99.93}
# 3 C 70.0964751 \\databar{70.1}
# 4 D 90.7419767 \\databar{90.74}
# 5 E 58.6721176 \\databar{58.67}
# 6 F 38.5582817 \\databar{38.56}
library(xtable)
print(xtable(d1), sanitize.text.function=function(x) x)
# \begin{table}[ht]
# \centering
# \begin{tabular}{rlrl}
# \hline
# & x1 & x2 & x3 \\
# \hline
# 1 & A & 0.29 & \databar{0.29} \\
# 2 & B & 99.93 & \databar{99.93} \\
# 3 & C & 70.10 & \databar{70.1} \\
# 4 & D & 90.74 & \databar{90.74} \\
# 5 & E & 58.67 & \databar{58.67} \\
# 6 & F & 38.56 & \databar{38.56} \\
# \hline
# \end{tabular}
# \end{table}
Note that you have to redefine the sanitize.text.function
parameter, so be careful to special characters.