Skip to main content
10 events
when toggle format what by license comment
Aug 23, 2016 at 14:16 comment added Szabolcs @glS I described how I manage my packages here. You may find it useful. I do not claim that this is the best way, in fact I'm pretty sure it isn't. But it does help me. It's something that grew out organically of my own needs, not something deliberately designed to be generally usable.
Aug 23, 2016 at 13:47 vote accept glS
Aug 23, 2016 at 13:47 comment added glS all right, I think I got it. It is also explained in a section of the (very useful) documentation page you provided in the answer. There is no public project yet no, I was considering what the best approach was to make some packages I have more modular and still be able to import and ship them easily between computers. This was very helpful, thanks again!
Aug 23, 2016 at 13:27 comment added Szabolcs @glS Is your application public by any chance? If yes, we can discuss it as an example.
Aug 23, 2016 at 13:24 comment added Szabolcs @glS Very often, there is a sinlge main package file, Foo/Foo.m and init.m only contains Get["Foo`Foo`"]. Then as your package is growins and you decide to add more sub-packages that Foo.m will depend on, you add them in the same directory as .m files and load them in Foo.m using BeginPackage["Foo`", {"Foo`Sub1`, ...}].
Aug 23, 2016 at 13:22 comment added Szabolcs @glS Say the package is called Foo. Then you have a directory with the same name. Within you have multiple .m files, Sub1.m, Sub2.m, etc. The init.m file contains Get["Foo`Sub1`"]; Get["Foo`Sub2`"]; .... You can load the whole package from a notebook using <<Foo` . If the sub-packages are somewhat independent and are meant to be loadable separately too, then that can be accomplished using <<Foo`Sub1` , i.e. the same commands used in init.m.
Aug 23, 2016 at 12:52 comment added glS by the way, I didn't find a clear explanation of what init.m does when inside a package directory structure. Can it be used for such purpuses?
Aug 23, 2016 at 12:51 comment added glS makes sense. But what if I for example have a big and complex package, composed of multiple .m files. I would want the whole thing to be contained in a single directory so to be easily moved and "installed", and at the same time to be able to easily import it in a notebook without having to think of the full paths. What is the recommended method in this case? Should I put a foo.m file where you put it in your example, and in foo.m write some code to tell MMA where to find the various "subpackages" necessary for the main one?
Aug 23, 2016 at 12:42 history edited Szabolcs CC BY-SA 3.0
added 3 characters in body
Aug 23, 2016 at 12:31 history answered Szabolcs CC BY-SA 3.0