MathGroup Archive 2002

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Package Problems

  • To: mathgroup at smc.vnet.net
  • Subject: [mg34442] Re: [mg34373] Package Problems
  • From: Omega Consulting <omega_consulting at yahoo.com>
  • Date: Tue, 21 May 2002 03:36:18 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

I encountered a couple of problems with your package, but the one causing 
these messages is due to context. The BeginPackage command is used to both 
load necessary packages and make symbols from those contexts available to 
your code.

Many programmers forget the second part and assume that all loaded symbols 
are available to the package. This is a common error when working with the 
Statistics packages because many of the symbols are not in the packages you 
load directly, but packages loaded by other packages.

In[1]:= <<Statistics`

In[2]:= Context[BestFitParameters]
Out[2]= Statistics`Common`RegressionCommon`

Instead, use the following for your BeginPackage

BeginPackage["MyPackages`gliba`",
   {"Statistics`DataManipulation`", "Statistics`DescriptiveStatistics`",
    "Statistics`LinearRegression`", "Statistics`Common`RegressionCommon`"}
]

--------------------------------------------------------------
Omega Consulting
"The final answer to your Mathematica needs"

Spend less time searching and more time finding.
http://www.wz.com/internet/Mathematica.html

At 05:30 AM 5/17/2002, Aaron wrote:
>I have been having trouble getting functions to work in Packages that
>I have created.  I have had this problem on a number of occasions,
>some of which I have fixed (usually I have no idea why it worked when
>I fixed it, but I don't complain).  I have included an excerpt from a
>package below with a particularly troublesome function that I haven't
>been able to fix.  The package loads fine, but when I call the
>function I get the following error:
>________________________________________________________________________
>data2=MSCorrect[data];
>
>MyPackages`gliba`Private`BestFitParameters
>
>Part::partd: Part specification
>MyPackages`gliba`Private`BestFitParameters[[1]] is longer than depth
>of object.
>
>Part::partd: Part specification
>MyPackages`gliba`Private`BestFitParameters[[2]]
>is longer than depth of object.
>_______________________________________________________________________
>
>
>I put the packages in the Applications directory in a folder called
>MyPackages.  The function takes a rectangular matrix of real values.
>If I copy the function into a notebook and compile it there it works
>fine.
>
>Thanks In Advance For Any Help,
>Aaron
>
>
>Here is the excerpt from the package.  It contains alot more functions
>than this, most of which work fine.  I get the same error when I use
>this reduced package.
>
>_______________________________________________________________________
>BeginPackage["`gliba`"]
>
>GLiba::usage =
>"GLib is a package that serves as a chemometric toolbox for analysis
>of real data sets."
>
>MSCorrect::usage =
>"newspec = MSCorrect[tnspec]. The scatter corrected spectra
>  (newspec) are returned from the input spectra (tnspec)."
>
>
>Begin["`Private`"]
>
>Needs["Statistics`DataManipulation`"]
>Needs["Statistics`DescriptiveStatistics`"]
>Needs["Statistics`LinearRegression`"]
>
>MSCorrect[tnspec_List]:=
>Module[{norows,nocols,temp,i,coeff,x,output,outspec},
>         {norows, nocols} = Dimensions[tnspec];
>         temp = Table[0, {2}, {nocols}];
>         outspec = Table[0, {norows}, {nocols}];
>         temp[[1]] = Mean[tnspec];
>         For[i = 1, i < norows + 1, ++i,
>                 temp[[2]] = tnspec[[i]];
>                 output = Regress[Transpose[temp], {x},{x},
>RegressionReport->{BestFitParameters}];
>                 coeff = BestFitParameters /. output;
>                 Print[coeff];
>                 outspec[[i]] = (tnspec[[i]] - coeff[[1]])/coeff[[2]];
>         ];
>         Return[outspec]
>];
>
>
>End[ ]
>
>EndPackage[ ]



  • Prev by Date: Re: Re: Re: Help! How to calculate additive partitions?
  • Next by Date: Re: Problem with Precision?
  • Previous by thread: Re: Package Problems
  • Next by thread: A possible bug in Lists