0
$\begingroup$

I need to use a number of functions from theStatistics`Library` namespace. Since that is a bit of a mouthful I would like to import it, but I get errors:

In[42]:= Needs["Statistics`Library`"]

During evaluation of In[42]:= Get::noopen: Cannot open Statistics`Library`. >>

During evaluation of In[42]:= Needs::nocont: Context Statistics`Library` was not created when Needs was evaluated. >>

Out[42]= $Failed

In[43]:= << Statistics`Library`

During evaluation of In[43]:= Get::noopen: Cannot open Statistics`Library`. >>

Out[43]= $Failed

I can use individual functions from the namespace

In[44]:= Statistics`Library`DistributionDimensionality[

NormalDistribution[]]

Out[44]= 1

so the problem is not in the name.

What is the problem then? What is the correct way to do the import?

$\endgroup$
2
  • $\begingroup$ I don't think you can "load" these in that way (could be wrong though), why not just set up some aliases, e.g. ``dd = StatisticsLibraryDistributionDimensionality, then dd[NormalDistribution[]]` does it... $\endgroup$
    – ciao
    Apr 19, 2014 at 23:06
  • 2
    $\begingroup$ It's a good idea to give some context for your question and link back to the original thread that prompted this. Statistics`Library` is not a package, so it can't be loaded. (Loading is triggered by the use of some other stats functions.) It is a context (namespace) containing functions meant for internal use: there's no documentation, no guarantee these functions will work properly or that they won't crash your kernel or cause memory leaks, and they're likely to change in future versions. $\endgroup$
    – Szabolcs
    Apr 19, 2014 at 23:26

1 Answer 1

7
$\begingroup$

Statistics`Library` does not correspond directly to a package path, so it cannot be loaded with Get or Needs. Rather, this contents of this context come from

FileNameJoin[{
 $InstallationDirectory, "SystemFiles", "Kernel", "SystemResources", $OperatingSystem,
 "Statistics", "Library.mx"
}]

which is loaded automatically at startup. Loading this file populates the context, but does not add anything to the context path.

It is straightforward to change the context path, however:

AppendTo[$ContextPath, "Statistics`Library`"]

Now:

DistributionDimensionality@NormalDistribution[] (* -> 1 *)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.