0

I am used to Python, and to a syntax like

import mypackage
import myotherpackage as mop
x = mypackage.calc(y)
z = mop.calc(y)

Am I right in understanding that R, like Matlab, does not have a proper namespace? I am a beginner in R.

How do you address conflict names?

What if two packages have the same function names?

If in R you do

library(mylib)
library(my_second_lib)

and both libraries have the function calc(), does calling calc() mean calling the function of the most recently loaded package?

How do you test two versions of a package? Eg if you want to test the output of your new package vs the output of the old one, and they both have the same function names?

halfer
  • 19,824
  • 17
  • 99
  • 186
Pythonista anonymous
  • 8,140
  • 20
  • 70
  • 112
  • 5
    you can call them using `mylib::calc()`, `my_second_lib::calc()` – Ronak Shah Mar 31 '19 at 08:51
  • Brilliant! Is this standard practice, though? I had never seen this syntax in the R code snippets I have come across – Pythonista anonymous Mar 31 '19 at 08:54
  • 1
    Yes, it's a standard practice. Especially when officially publishing code (ie, submitting to CRAN). However, most of the time people use `library` as they work with 1-10 packages at a time. – pogibas Mar 31 '19 at 09:02
  • Can you assign an alias to a library? Eg you load my_amazing_library and then you run something like mal::calc() instead of my_amazing_library::calc() ? Or is there no alternative to spelling out the full name of the library? – Pythonista anonymous Mar 31 '19 at 09:17
  • 2
    If you're looking for something like `import numpy as np`, you can check this thread: https://stackoverflow.com/q/24391251/11117265 – yarnabrina Mar 31 '19 at 09:20
  • Ronak, how about using source to load another script I made (NOT a package)? Is there a way to specify myscript::myfun() in that case, too? – Pythonista anonymous Mar 31 '19 at 22:34

0 Answers0