[BioC] xtable links
James W. MacDonald
jmacdon at med.umich.edu
Fri Dec 5 22:30:51 CET 2008
Hi Tim,
Tim Smith wrote:
> Hi,
>
> I was trying to get hyperlinks using xtable, but couldn't get the hyperlinks to function properly. For example, if I use
>
> ## Try to link NY times website to every figure in column 4
> mat <- matrix(1:43,6,5)
> mat[,5] <- "http://nytimes.com"
>
> for(i in 1:nrow(mat)){
> strr <- paste('<a href="', mat[i,5],'">', mat[i,4], '</a>', sep='')
> mat[i,4] <- strr
> }
> mat2 <- mat[,1:4]
>
> caption = 'test'
> mx <- xtable(mat2,caption=caption)
> tt = print(mx, type="html",include.rownames=F)
> tt1 <- gsub('lt /a','lt/a',tt,fixed=T)
> tt2 <- gsub('lt a','lta',tt1,fixed=T)
Your html is malformed:
> mat2
[,1] [,2] [,3] [,4]
[1,] "1" "7" "13" "<a href=\"http:\\www.nytimes.com\">19</a>"
[2,] "2" "8" "14" "<a href=\"http:\\www.nytimes.com\">20</a>"
[3,] "3" "9" "15" "<a href=\"http:\\www.nytimes.com\">21</a>"
[4,] "4" "10" "16" "<a href=\"http:\\www.nytimes.com\">22</a>"
[5,] "5" "11" "17" "<a href=\"http:\\www.nytimes.com\">23</a>"
[6,] "6" "12" "18" "<a href=\"http:\\www.nytimes.com\">24</a>"
So you need to fix that first (e.g.,
"<A href="http:\\www.nytimes.com\">19</A>")
In addition, you don't use write.table() with xtable. You want to use
print(mx, file="test.html", type="html")
Also you might want to add caption.placement="top" if you want the
caption to be at the top of the page.
Best,
Jim
>
> write.table(tt2,'test.html',quote=F)
>
> However, if I open 'test.html' in IE, the hyperlinks don't seem to work. What am I doing wrong?
>
> thanks.
>
>
>
> [[alternative HTML version deleted]]
>
> _______________________________________________
> Bioconductor mailing list
> Bioconductor at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/bioconductor
> Search the archives: http://news.gmane.org/gmane.science.biology.informatics.conductor
--
James W. MacDonald, M.S.
Biostatistician
Hildebrandt Lab
8220D MSRB III
1150 W. Medical Center Drive
Ann Arbor MI 48109-0646
734-936-8662
More information about the Bioconductor
mailing list