Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Avoid auto-hyperlink generation with knitr, markdown

knitr automatically generates links when knitting .Rmd to .html. Very often that's useful, but just now it's not what I want.

Suppose you have this .Rmd file:

---
title: "Doc title"
output: html_document
---

I don't want [email protected], but it comes out that way. 

If you wrap it in an R expression  `r "[email protected]"`.

Is there some kind of CSS trick I can avail myself of if I wanted <style='nolink'>www.something.com</style> not to be a link?

Knitting like this:

library(knitr)
knit2html('that_file.Rmd', 'that_file.html')

results in all those things being links.

enter image description here

Is there an easy way to generally keep the auto-link generation, but disable it selectively in particular lines? Thanks for any thoughts.

Edit: i guess I should have actually tried the solution below before accepting. This in the .Rmd

I don't want this <!-- breaklink -->@to-be-a-link.com

...doesnt actually parse to an HTML comment, because the -- gets changed to an em dash (by knitr? pandoc?) and then I get:

enter image description here

like image 683
arvi1000 Avatar asked Jan 05 '15 04:01

arvi1000


People also ask

How not include output in R Markdown?

You use results="hide" to hide the results/output (but here the code would still be displayed). You use include=FALSE to have the chunk evaluated, but neither the code nor its output displayed.

Does R Markdown use Pandoc?

A recent version of Pandoc (>= 1.12. 3) is required to use the rmarkdown package. RStudio also automatically includes this so you do not need to download Pandoc if you plan to use rmarkdown from the RStudio IDE. If not using the RStudio IDE, you'll need to install Pandoc for your platform.

How do you hyperlink in RMD?

Hyperlinks are created using the syntax [text](link) , e.g., [RStudio](https://www.rstudio.com) . The syntax for images is similar: just add an exclamation mark, e.g., ![ alt text or image title](path/to/image) . Footnotes are put inside the square brackets after a caret ^[] , e.g., ^[This is a footnote.] .


1 Answers

Two options that I see are (1) using bare backticks, or (2) "breaking" the link by using an empty HTML comment.

Example:

---
title: "Doc title"
output: html_document
---

I don't want this<!-- -->@to-be-a-link.com, but it comes out that way. 

If you wrap it in an R expression `[email protected]`.

Is there some kind of CSS trick I can avail myself of if I wanted 
<style='nolink'>http<!-- -->://www.something.com</style> not to 
be a link?

Becomes:

enter image description here

like image 91
A5C1D2H2I1M1N2O1R2T1 Avatar answered Oct 20 '22 15:10

A5C1D2H2I1M1N2O1R2T1