Jennifer Liu
Jennifer Liu

Reputation: 591

How do I add a URL to R markdown?

I want to refer a URL link to the R markdown and I already tried the input such as "addlink" or "address <- ...." Both of them do not work. How can I add a link in R markdown?

Thanks!

EDIT: op's code from comment was

   {r} [linked phrase] (www.bit.ly/1EqAdIp)

Upvotes: 57

Views: 149250

Answers (5)

Haley Huston
Haley Huston

Reputation: 41

If you want to add an internal link to your RMD, that is reference the appendix from the summary section, ex:

summary

link here to heading 2 of appendix section

appendix

Heading 2 of Appendix

you would add the following (note this is case-sensitive, everything is now lower-case and spaces are exchanged with hyphens):

# summary

**[name of link](#heading-2-of-appendix)**

```{r}
```

# appendix

```{r}
```

## Heading 2 of Appendix

Also, note that in the reference to the heading-2-of-appendix, there is only one #, regardless of the type of heading the section-to-be-referenced is in.

Upvotes: 3

Saifuddin_StatLab
Saifuddin_StatLab

Reputation: 41

You can try this code to add a url which represent the topic.

[ggrepel](https://github.com/slowkow/ggrepel)

That is:

[topic](url)

Upvotes: 4

DrRDN
DrRDN

Reputation: 328

If you are using shiny, all you need to do is at the markup (white) area:

[linked phrase](www.bit.ly/1EqAdIp) #no space, no {r}

This way you enter the hyperlink at the text(=markup) and not the interactive portion(~R) of your page.

Upvotes: 14

Scransom
Scransom

Reputation: 3335

Noting @Hao's answer below, that this must be in the main text, not within a code block:

From this fabulous resource

[I'm an inline-style link](https://www.google.com)

[I'm an inline-style link with title](https://www.google.com "Google's Homepage")

[I'm a reference-style link][Arbitrary case-insensitive reference text]

[I'm a relative reference to a repository file](../blob/master/LICENSE)

[You can use numbers for reference-style link definitions][1]

Or leave it empty and use the [link text itself]

Some text to show that the reference links can follow later.

[arbitrary case-insensitive reference text]: https://www.mozilla.org
[1]: http://slashdot.org
[link text itself]: http://www.reddit.com

Upvotes: 85

Hao
Hao

Reputation: 7856

You shouldn't put the hyperlink inside the R code block. xxx is the Markdown syntax. If you put it after {r}, knitr/rmarkdown will treat it as part of the R code and, of course, R will produce an error message.

Solution: remove {r}

Upvotes: 8

Related Questions