title: How to import an .R file and assign an alias to it? Like import myfile.R as mf
body: <p>R beginner here, who really misses Python's</p>
  
  <pre><code>import pandas as pd
  import my_file_which_is_just_a_file_not_a_package as mf
  out = mf.my_cool_function()
  </code></pre>
  
  <p>I have found a way to implement something similar to the former (assigning an alias to a package), but how to do the latter, i.e. <strong>how to assign an alias to an .R file (not a package) you are importing?</strong> E.g. you have put some functions you use frequently into a separate .R file, or you are dividing your program into multiple .R files to keep things tidy.</p>
  
  <p>NB: this is NOT a duplicate of questions asking how to assign an alias to a package - I am talking about single R files, not packages.</p>
  
  <p>I understand that the namespace library provides a functionality similar to <code>import as</code> for installed packages:</p>
  
  <pre><code>library(namespace)
  registerNamespace('ggp', loadNamespace('ggplot2'))
  data(iris)
  ggp::ggplot(iris, ggp::aes(x = Petal.Length, y = Sepal.Length)) + ggp::geom_point()
  </code></pre>
  
  <p>I also understand that you can use import to import only certain functions from another .R file, e.g. from another script (not a package):</p>
  
  <pre><code>import::here(fun_a, fun_b, .from = "other_resources.R")
  a &lt;- fun_a(…)
  </code></pre>
  
  <p>Finally, you can use <a href="https://www.rdocumentation.org/packages/base/versions/3.5.3/topics/source" rel="nofollow noreferrer">source</a> to load another script.</p>
  
  <p>But none of this addresses my point about importing with an alias.</p>
  
  <h2>Edit</h2>
  
  <p>Since I was asked, I am trying to learn some R because:</p>
  
  <ul>
  <li>I am curious; last time I tried R was before the tidyverse "revolution"; I hated it at the time, found it obscure, arcane, and with extremely poor documentation. Everyone's saying how wonderful tidyverse is, so I'm curious to give R another try</li>
  <li>I am unlikely to migrate all my workflow from Python to R, but there might be certain things that I might want to do in R. An example is reading large Excel files and exporting to SQL; both of these tasks are much faster in R. I can now import large xlsx files into SQL in a fraction of the time, then get Python to read from SQL and leave the rest of my workflow unchanged. I posted about it <a href="https://stackoverflow.com/questions/55513145/fastest-way-to-read-large-excel-xlsx-files-to-parallelize-or-not">here</a>, where I also explained why CSV is not the best option for me (please do not reply saying 'use CSV').</li>
  </ul>