0

I have a bunch of .R files in a directory (classes with inheritance). These files depend on each other.

I need to use these files' classes in a file in a different directory.

Is there a way to directly call their functions/classes from a file in a different location? Maybe by adding them to some kind of path? I was thinking of including each source file manually but they are numerous.

DanyAlejandro
  • 1,440
  • 13
  • 24
  • 1
    It sounds like you should make a proper package to share those class. R doesn't every automatically read code from a directory outside of a package. You would otherwise need to explicitly source() all those files. Making a package is really pretty simple. Maybe this guide can help: https://hilaryparker.com/2014/04/29/writing-an-r-package-from-scratch/ or this one: https://kbroman.org/pkg_primer/ – MrFlick Dec 05 '19 at 20:25
  • Yeah, they are a part of a package right now. I'm trying to avoid having to build them as a package every time I make a small modification. – DanyAlejandro Dec 05 '19 at 20:28
  • Then it's unclear to me exactly what the problem is. It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. It's not too hard to source a bunch of files at once. For example: https://gist.github.com/johnatasjmo/f6073976b5e1aac3d755ee1852a3aca5 – MrFlick Dec 05 '19 at 20:31

0 Answers0