Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Say I have a toy package, something like:

BeginPackage["myPackage`"]
plotSomeData::usage = "plotFinancialData[symbol]... some usage language";
Begin["`Private`"]
plotSomeData[symbol_]:= DateListPlot[FinancialData[symbol, All]]
End[]
EndPackage[]

This should work fine, nothing particularly complicated here.

So now, I'd like to extend the FinancialData[] function embedded in the package to enable it to seamlessly access non-Wolfram curated data stored locally on my computer.

I could rewrite the package and set up some conditional code that would replace FinancialData[] with Import[], something like:

plotSomeData[symbol_] := DateListPlot[
  Which[
   symbol == "xyz", Import[pathAndFileName],
   symbol != "xyz", FinancialData[symbol, All]
   ]]

But, in my case, that would mean rewriting a bunch of perfectly good packges, so I'd like another solution. Some of the questions and answers such as:

What is a paclet?

UpValues TagSet and UpSet

have me wondering if another more elegant way exists to do this.

Could, for instance, one extend the paclet information for a set of curated data?

I've used TagSet before to do things like define how to calculate the CDF of a custom distribution, but I don't see a clear way to use it to enable a curated data function to recognize the location of a data symbol it doesn't already know.

SetOptions doesn't seem like the thing either.

UpVales and UpSet might do it, but I don't see it yet.

Ideally, I'd simply like to extend a curated data function to recognize the location of a data symbol it doesn't already know and thereby enable it to get the newly identified data.

Best if I can do this outside of the packages I already have.

Any ideas?

(The tags I have on this question could use some improvement, if anyone has some better ideas.)

share|improve this question
    
You can't add rules to FinancialData, since it is Locked. As you mentioned yourself, UpValues can help. You can define a given symbol as sym/: FinancialData[sym,...]:=..., where you can insert on the r.h.s. the definition you want. –  Leonid Shifrin Apr 17 '13 at 0:17
    
@LeonidShifrin -- I think I understand. The r.h.s would become my Import[pathAndFileName]. That should enable me to do additional statements for other symbols that would correspond to their own data sets? –  Jagra Apr 17 '13 at 2:03
    
Yes, that's right. –  Leonid Shifrin Apr 17 '13 at 11:19
    
@LeonidShifrin -- Certainly worthy of an accepted answer in my opinion. If you want to post it, you've got my vote. - Thx. –  Jagra Apr 17 '13 at 16:09
    
No time for it at the moment, alas. Will do when I get some window, unless someone does that first. Also, feel free to post your own answer based on the hints I gave, and accept that. –  Leonid Shifrin Apr 17 '13 at 16:16
show 4 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.