title: Rmarkdown output rendering based on condition
body: <p>I am trying to build in an automated way a Word document that will display a list of Youtube video links I want to watch with Youtube Title video as text and the Youtube url as a hyperlink.</p>
  <p>I have used Rmarkdown to do that and it works well with a defined number of urls.<br />
  But my issue is that I want that Rmarkdown document to work with any number of urls as input of my <code>Links.txt</code> file.</p>
  <p>As an example, the content of the <code>Links.txt</code> file could simply be:</p>
  <pre><code>https://www.youtube.com/watch?v=NDDUMon9SJM  
  https://www.youtube.com/watch?v=x9iAD3GZyfM  
  https://www.youtube.com/watch?v=fHhNWAKw0bY  
  https://www.youtube.com/watch?v=jYUZAF3ePFE  
  https://www.youtube.com/watch?v=ik4USIChrkY  
  https://www.youtube.com/watch?v=HgEGAaYdABA  
  </code></pre>
  <p>Is there a way to use a if condition of some sort to display the exact number of urls each time?</p>
  <p>The only post that seems related is this <a href="https://stackoverflow.com/questions/25407102/conditionally-display-a-block-of-text-in-r-markdown">one</a> but I don't really see a working solution.</p>
  <p>Here is my current code:</p>
  <pre><code>---
  title: &quot;Hyperlinks_Word&quot;
  output: word_document
  ---
  
  ```{r setup, include=FALSE}
  knitr::opts_chunk$set(echo = FALSE)
  
  library('rvest')
  library('magrittr')
  library('httr')
  
  ```
  
  
  ```{r }
  
  url_proxy &lt;- read.table(&quot;Links.txt&quot;, header = FALSE, sep = &quot;&quot;)
  
  url_proxy &lt;- as.character(url_proxy$V1)
  
  link_test &lt;- list()
  
  for(i in 1:length(url_proxy)){
    
    download.file(url_proxy[i], destfile ='scrape_test.html',quiet = TRUE)
    
    url &lt;- read_html('scrape_test.html')
    
    youtube_title &lt;- url%&gt;%html_nodes(xpath = &quot;//title&quot;)%&gt;%html_text()
    youtube_title &lt;- data.frame(matrix(unlist(youtube_title), nrow=length(youtube_title), byrow=T))
    colnames(youtube_title) &lt;- &quot;youtube_title&quot;
  
    link_test[i] &lt;- as.character(youtube_title$youtube_title)
    
  }
  
  
  ```
  
  
  `r i=1`
  
  [`r link_test[i]`](`r url_proxy[i]`)  
  
  `r i=2`
  
  [`r link_test[i]`](`r url_proxy[i]`)  
  
  `r i=3`
  
  [`r link_test[i]`](`r url_proxy[i]`)  
  
  `r i=4`
  
  [`r link_test[i]`](`r url_proxy[i]`)  
  </code></pre>