I am not sure if I understand you correctly. If I do xtable (foo), then% is correctly escaped:
... \hline 1 & \% \\ \hline ...
If you want to make a collage slash for something else, you will need a four in gsub:
> x <- gsub('%', '\\\\%', foo[,1]) > x [1] "\\%" > cat(x,"\n") \%
Remember, you cannot gsub in a dataframe, only in a vector. It can be shown
> as.character(foo) [1] "1"
Joris meys
source share