title: How to Make my R script executable?
body: <p>I am aware this is at high risk of being a duplicate, but in none of the other questions here I have found an answer to my problem. Below is a summary of what I have already tried.</p>
  
  <p>I have an R script file <code>file.r</code>:</p>
  
  <pre><code>#!/usr/bin/env Rscript 
  print("Hello World!")
  </code></pre>
  
  <p>which is executable (<code>chmod +x file.r</code>), and which used to run nicely (last time I used it was about a month ago) by issuing:</p>
  
  <pre><code>$ ./file.r
  </code></pre>
  
  <p>However, today: </p>
  
  <pre><code>$ ./file.r
  /usr/bin/env: 'Rscript\r': No such file or directory
  </code></pre>
  
  <p>In fact:</p>
  
  <pre><code>$ which Rscript
  /usr/bin/Rscript 
  </code></pre>
  
  <p>Thus I changed shebang to: <code>#!/usr/bin Rscript</code>, but:</p>
  
  <pre><code>$ ./file.r
  /usr/bin: bad interpreter: Permission denied
  </code></pre>
  
  <p>Then I thought I would run it as super user, but:</p>
  
  <pre><code>$ sudo ./file.r
  sudo: unable to execute ./file.r: Permission denied
  </code></pre>
  
  <p>Reading around I found that a fresh installation of R would solve my problem, so I un-installed and installed R. Unfortunately what I have written before still applies. Notice however that the following works with both shebang versions:</p>
  
  <pre><code>$ Rscript file.r
  [1] "Hello World!"
  </code></pre>
  
  <p>What am I doing wrong?</p>