juanfung / scpd

0 stars 0 forks source link

Problem accessing packages loaded in module `CausalMixtures` #9

Closed juanfung closed 5 years ago

juanfung commented 5 years ago

In v0.5, module CausalMixtures could, eg, load package like so: using DataFrames

Then when using module CausalMixtures, eg, in causal-sims.jl, I could simply do:

df = DataFrames.DataFrame(A = 1:4, B = ["M", "F", "F", "M"])

Now, in v0.7, this doesn't work. Package DataFrames is not bound to Main but rather to CausalMixtures, which requires this:

df = CausalMixtures.DataFrames.DataFrame(A = 1:4, B = ["M", "F", "F", "M"])

This seems a little clunky.

This also works: df = CausalMixtures.DataFrame(A = 1:4, B = ["M", "F", "F", "M"]), which is all sorts of confusing!

What is the best practice for loading and using packages via a module?

juanfung commented 5 years ago

Could this be addressed by packaging dependencies? https://docs.julialang.org/en/v0.7/stdlib/Pkg/#Creating-your-own-packages-1

juanfung commented 5 years ago

Problem is not addressed by packaging dependencies. Tested on a toy module based on example in the docs.

Since this is only a problem for running scripts (ie, no problem running functions defined in the module that use external packages), best solution may be to simply load required packages at the top of the script.

An alternative solution is to export from module CausalMixtures (eg, `export DataFrames). I tested this with the toy module and it works if the module is loaded via using.

In addition, the following packages are used to generate figures and tables but not explicitly loaded:

juanfung commented 5 years ago

This commit loads the last two packages into figtab_dpm.jl 792862a398ab62dc64cc68992871fe47a212fe1a

juanfung commented 5 years ago

This commit exports the packages listed in comment above for use in scripts 101d13360f45b6098431965f05c8687d99230fe3