title: R equivalent of python -m module for an R package
body: <p>I have an R script that can be executed in a terminal with <code>Rscript app/myapp.R</code>. The R script is stored in an R package project so that I can benefit from the documentation, check and unit tests tools.</p>
  
  <p>Just for the sake of user-friendlyness, I was wondering if there is a method to mimic python's behaviour of a <code>__main__.py</code> inside a module.</p>
  
  <p>EDIT 6/1/2020 : I actually need other users, that are not accustumed to R, to use the script. So once the package is installed, finding the full path of the script is not really an option for them.</p>
  
  <hr>
  
  <p>In a python project, when I have the following package structure :</p>
  
  <pre class="lang-sh prettyprint-override"><code>mypackage
  ├── mymodule
  │   ├── __init__.py
  │   └── __main__.py
  └── setup.py
  </code></pre>
  
  <p>I can do <code>python -m mymodule</code> <em>from any folder in the terminal</em> provided the package was indeed installed in my python library. The command will execute <code>mypackage/mymodule/__main__.py</code>.</p>
  
  <p>I'd like to have the same behaviour for an R package. Let's assume that the R package <code>mypackage</code> is already installed in my R user's library. I would like to be able to run <code>mypackage/app/myapp.R</code> from anywhere in the terminal (actually, I'd like others to be able to install the package and run the app without having to clone the repo).</p>
  
  <p>I know that I can do </p>
  
  <pre class="lang-sh prettyprint-override"><code>Rscript app/myapp.R
  </code></pre>
  
  <p>but that will only work if I <code>cd</code> into <code>path/to/mypackage</code>. I'd like to be able to do something like below <em>from anywhere in the terminal provided the package is installed in the R user's library</em>.</p>
  
  <pre class="lang-sh prettyprint-override"><code>Rscript -m myapp
  </code></pre>
  
  <p><code>demo()</code> seems to be made for interactive sessions and I need a non-interactive session.</p>