Sorry, I forgot to give you a quick example of 'wrapping in plot'

plot(addTA(...))

The objects returned by most of the charting functions in quantmod results
from the desire for the functions to be syntactically identical whether
called from inside of chartSeries (e.g. TA="addMACD()" ) as they are from
outside:

R> addMACD()

The code the simplicity of this (and the lack of need for documenting 2
different functions, and learning all the details of 2 different functions
(2x the work)) you need to be a bit clever in how R works.  Describing that
is 1) not simple and 2) ironically, not very well documented in base R.  For
me to write it I just had to get around number 2.

HTH
Jeff

On Thu, May 5, 2011 at 11:55 AM, Jeff Ryan <jeff.a.r...@gmail.com> wrote:

> There is a struggle in documentation that revolves around being too brief
> to be useful and too verbose which then is often ignored.  In general, R
> "proper" is far less verbose than quantmod docs - so if you have trouble
> with quantmod...
>
> from ?addTA
>
> Value:
>
>      ‘addTA’ will invisibly return an S4 object of class ‘chobTA’. If
>      this function is called interactively, the ‘chobTA’ object will be
>      evaluated and added to the current chart.
>
>      ‘newTA’ will return a function object that can either be assigned
>      or evaluated.  Evaluating this function will follow the logic of
>      any standard addTA-style call, returning invisibly a ‘chobTA’
>      object, or adding to the chart.
>
> In addition there is a "see also" that references ?TA
>
> One can also use the archives to see this "problem" discussed over and
> over.  It isn't for lack of documentation typically - it is for lack of
> looking.
>
> That said, could the docs be more clear/verbose?  Certainly.  Does that
> take time?  Certainly.  Does answering the same question in a public forum
> take time? Certainly.  What the latter does though is provide for an
> excellent reference for those who misunderstand or don't understand the
> 'Value' aspect of the docs (which here explains quite clearly that nothing
> is printed by the call itself).
>
> A suitably phrased patch for the docs is one way to contribute in a
> productive manner - though it may not always be applied by those you submit
> it to (to me or any of the other 3000 package author/maintainers/etc).
>
> HTH
> Jeff
>
> On Thu, May 5, 2011 at 11:42 AM, Russ Abbott <russ.abb...@gmail.com>wrote:
>
>> Thanks. You're right. I didn't see that.  I read the ?addTA help page,
>> which (annoyingly) didn't mention that feature, but I didn't read the ?TA
>> page. (That page was mentioned as a see also, but not as a must see.)
>>
>> I don't know what it means to wrap these calls in a plot call. I tried to
>> put the addTA calls into a function and call that function from the higher
>> level function, but that didn't work either. Would you tell me what it means
>> to wrap these calls in a plot call.
>>
>> Thanks
>>
>> *-- Russ *
>>
>> P.S. Pardon my irritation, but I continually find that many of the help
>> files assume one already knows the information one is looking for. If you
>> don't know it, the help files are not very helpful.  This is a good example.
>>  In fact, it's two good examples.  I didn't know that I had to look at
>> another page, and I (still) don't know what it means to wrap plot calls in
>> another plot call.
>>
>>
>> On Thu, May 5, 2011 at 3:39 AM, P Ehlers <ehl...@ucalgary.ca> wrote:
>>
>>> On 2011-05-05 0:47, Russ Abbott wrote:
>>>
>>>> Hi,
>>>>
>>>> I'm having trouble with quantmod's addTA plotting functions.  They seem
>>>> to
>>>> work fine when run from the command line. But when run inside a
>>>> function,
>>>> only the last one run is visible.  Here's an example.
>>>>
>>>>
>>>> test.addTA<- function(from = "2010-06-01") {
>>>>     getSymbols("^GSPC", from = from)
>>>>     GSPC.close<- GSPC[,"GSPC.Close"]
>>>>     GSPC.EMA.3<- EMA(GSPC.close, n=3, ratio=NULL)
>>>>     GSPC.EMA.10<- EMA(GSPC.close, n=10, ratio=NULL)
>>>>     chartSeries(GSPC.close, theme=chartTheme('white'), up.col="black",
>>>> dn.col="black")
>>>>     addTA(GSPC.EMA.3,   on = 1, col = "#0000ff")
>>>>     addTA(GSPC.EMA.10,  on = 1, col = "#ff0000")
>>>>     # browser()
>>>> }
>>>>
>>>>
>>>> When I run this, GSPC.close always appears.  But only GSPC.EMA10 appears
>>>> on
>>>> the plot along with it. If I switch the order of the addTA calls,
>>>> only GSPC.EMA3 appears. If I uncomment the call to browser() neither
>>>> appears
>>>> when the browser() interrupt occurs. I can then draw both GSPC.EMA.3 and
>>>> GSPC.EMA10 manually, and let the function terminate. All intended plots
>>>> are
>>>> visible after the function terminates. So it isn't as if one wipes out
>>>> the
>>>> other. This shows that it's possible to get all three lines on the plot,
>>>> but
>>>> I can't figure out how to do it without manual intervention. Any
>>>> suggestions
>>>> are appreciated.
>>>>
>>>
>>> Perhaps you didn't see this NOTE on the ?TA help page:
>>>
>>> "Calling any of the above methods from within a function
>>> or script will generally require them to be wrapped in a
>>> plot call as they rely on the context of the call to
>>> initiate the actual charting addition."
>>>
>>> Peter Ehlers
>>>
>>>
>>>> Thanks.
>>>>
>>>> *-- Russ *
>>>>
>>>>        [[alternative HTML version deleted]]
>>>>
>>>> ______________________________________________
>>>> R-help@r-project.org mailing list
>>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>>> PLEASE do read the posting guide
>>>> http://www.R-project.org/posting-guide.html
>>>> and provide commented, minimal, self-contained, reproducible code.
>>>>
>>>
>>
>
>
> --
> Jeffrey Ryan
> jeffrey.r...@lemnica.com
>
> www.lemnica.com
>



-- 
Jeffrey Ryan
jeffrey.r...@lemnica.com

www.lemnica.com

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to