sargas
sargas

Reputation: 558

How to markdown/html tables containing plus/minus

I use a chain of

knitr::knit2html("test.Rmd") # generates test.md & test.html
rmarkdown::render("test.md") # overwrites test.html

to generate an html report.

This chain provides good functionality as my report usually combines pictures, tables & text. If I ran only

knitr::knit2html("test.Rmd")

"test.html" will be generated, but it looks awkward, i.e. pictures not shown correctly.

Normally, this works fine, but this time sample names that are headers of a table contain '+' or '-'.

|               | IP_gene8-_1st| IP_gene8+_1st| 
|:--------------|-------------:|-------------:|
|IP_gene8-_1st  |     1.0000000|     0.4357325|
|IP_gene8+_1st  |     0.4357325|     1.0000000|

"test.html" generated by knit2html("test.Rmd") will contain a valid table, but other pictures are not shown correctly.

<table><thead>
<tr>
<th align="left"></th>
<th align="right">IP_Rad18-_1st</th>
<th align="right">IP_Rad18_1st</th>
</tr>
</thead><tbody>
<tr>
<td align="left">IP_Rad18_1st</td>
<td align="right">1.0000000</td>
<td align="right">0.4357325</td>
</tr>
<tr>
<td align="left">IP_Rad18_1st</td>
<td align="right">0.4357325</td>
<td align="right">1.0000000</td>
</tr>
</tbody></table>

Running rmarkdown::render("test.md") produces a "test.html" with a table as text only, but e.g. pictures shown correctly. The crappy table output looks like this:

| | IP_gene8-_1st| IP_gene8+_1st| |:-------------|-------------:|-------------:| |IP_Rad18_1st | 1.0000000| 0.4357325| |IP_Rad18_1st | 0.4357325| 1.0000000|

Usually, '+' and '-' can be protected using '/', but this does not have any effect in the table context.

Is there any way to trick rmarkdown::render() to create a valid html-table?

Upvotes: 4

Views: 9996

Answers (1)

Shital Shah
Shital Shah

Reputation: 68708

You can use below unicode entity code for +/- sign in markdown as well as html:

&#177;
&#xB1;
&pm;

Upvotes: 1

Related Questions