Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to insert image from url in markdown

The way to insert an image to markdown file is (and it is outside "{r}")

<center><src="http://ia.media-imdb.com/images/M/MV5BMTg4NzEyNzQ5OF5BMl5BanBnXkFtZTYwNTY3NDg4._V1._CR24,0,293,443_SX214_AL_.jpg"></center>

But I want to make url as a variable. So I tried something like this:

```{r, result='asis'}
url <- "http://www.online-image-editor.com//styles/2014/images/example_image.png"
print(paste("<center><src=\"", url, "\"></center>", collapse=""))
```

But it doesn't work. The result I get

## [1] "<center><src=\" http://ia.media-imdb.com/images/M/MV5BMTg4NzEyNzQ5OF5BMl5BanBnXkFtZTYwNTY3NDg4._V1._CR24,0,293,443_SX214_AL_.jpg \"></center>"

Is there any chance to make the string of characters like on the top of my question so get rid of ## [1] and quotes?

like image 214
jjankowiak Avatar asked Mar 07 '15 08:03

jjankowiak


People also ask

How do you add a URL to Markdown?

Markdown syntax for a hyperlink is square brackets followed by parentheses. The square brackets hold the text, the parentheses hold the link.

How do I link an image in GitHub Markdown?

You can display an image by adding ! and wrapping the alt text in [ ] . Then wrap the link for the image in parentheses () . GitHub supports embedding images into your issues, pull requests, discussions, comments and . md files.


1 Answers

We can do it using inline R code. For example:

```{r, echo=FALSE}
# Define variable containing url
url <- "http://www.online-image-editor.com//styles/2014/images/example_image.png"
```
## Some cat!
<center><img src="`r url`"></center>

## Alternatively...
![](`r url`)
like image 56
Richard Ambler Avatar answered Sep 17 '22 13:09

Richard Ambler