1. File is (was) saved. 2. The added code is t(tradeStats("macross")) with 2 )'s. I'd appreciate if someone with QuantStrat installed, to try this and see if they get a different result. My R and RStudio and QuantStrat libraries are all current. I get the chart and this much output. > source('~/CodingData/RCode/Quantstrat1/maCross.R') [1] "2001-06-27 00:00:00 AAPL 100 @ 1.526312" [1] "2001-09-07 00:00:00 AAPL -100 @ 1.13002" [1] "2002-01-07 00:00:00 AAPL 100 @ 1.497538" [1] "2002-07-10 00:00:00 AAPL -100 @ 1.132636" [1] "2003-05-16 00:00:00 AAPL 100 @ 1.22942" [1] "2006-06-22 00:00:00 AAPL -100 @ 7.792429" [1] "2006-09-26 00:00:00 AAPL 100 @ 10.150561" [1] "2008-03-07 00:00:00 AAPL -100 @ 15.988996" [1] "2008-05-19 00:00:00 AAPL 100 @ 24.012922" [1] "2008-09-24 00:00:00 AAPL -100 @ 16.833895" [1] "2009-05-14 00:00:00 AAPL 100 @ 16.080549" [1] "2012-12-11 00:00:00 AAPL -100 @ 71.436852" [1] "2013-09-11 00:00:00 AAPL 100 @ 62.897826" [1] "2015-08-31 00:00:00 AAPL -100 @ 110.399553" Time difference of 0.3014359 secs [1] "trade blotter portfolio update:" Time difference of 0.1732061 secs >
I have quantstrat installed and it works fine for me. If you're asking why the output of t(tradeStats('macross')) isn't being printed, that's because of what's described in the first paragraph in the *Details* section of help("source"): Note that running code via ?source? differs in a few respects from entering it at the R command line. Since expressions are not executed at the top level, auto-printing is not done. So you will need to include explicit ?print? calls for things you want to be printed (and remember that this includes plotting by ?lattice?, FAQ Q7.22). So you need: print(t(tradeStats('macross'))) if you want the output printed to the console. On Wed, Aug 31, 2016 at 10:26 AM, Doug Edmunds <dougedmunds at gmail.com> wrote:> 1. File is (was) saved. > 2. The added code is > t(tradeStats("macross")) > with 2 )'s. > > I'd appreciate if someone with QuantStrat installed, to try this > and see if they get a different result. My R and RStudio and > QuantStrat libraries are all current. > > > I get the chart and this much output. > >> source('~/CodingData/RCode/Quantstrat1/maCross.R') > [1] "2001-06-27 00:00:00 AAPL 100 @ 1.526312" > [1] "2001-09-07 00:00:00 AAPL -100 @ 1.13002" > [1] "2002-01-07 00:00:00 AAPL 100 @ 1.497538" > [1] "2002-07-10 00:00:00 AAPL -100 @ 1.132636" > [1] "2003-05-16 00:00:00 AAPL 100 @ 1.22942" > [1] "2006-06-22 00:00:00 AAPL -100 @ 7.792429" > [1] "2006-09-26 00:00:00 AAPL 100 @ 10.150561" > [1] "2008-03-07 00:00:00 AAPL -100 @ 15.988996" > [1] "2008-05-19 00:00:00 AAPL 100 @ 24.012922" > [1] "2008-09-24 00:00:00 AAPL -100 @ 16.833895" > [1] "2009-05-14 00:00:00 AAPL 100 @ 16.080549" > [1] "2012-12-11 00:00:00 AAPL -100 @ 71.436852" > [1] "2013-09-11 00:00:00 AAPL 100 @ 62.897826" > [1] "2015-08-31 00:00:00 AAPL -100 @ 110.399553" > Time difference of 0.3014359 secs > [1] "trade blotter portfolio update:" > Time difference of 0.1732061 secs > >> > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.-- Joshua Ulrich | about.me/joshuaulrich FOSS Trading | fosstrading.com R/Finance 2016 | rinfinance.com
Thank you. That explains it (auto-printing is not done). On 8/31/2016 8:35 AM, Joshua Ulrich wrote:> I have quantstrat installed and it works fine for me. If you're > asking why the output of t(tradeStats('macross')) isn't being printed, > that's because of what's described in the first paragraph in the > *Details* section of help("source"): > > Note that running code via ?source? differs in a few respects from > entering it at the R command line. Since expressions are not > executed at the top level, auto-printing is not done. So you will > need to include explicit ?print? calls for things you want to be > printed (and remember that this includes plotting by ?lattice?, > FAQ Q7.22). > > So you need: > > print(t(tradeStats('macross'))) > > if you want the output printed to the console. >
On R-help, with subject '[R] source() does not include added code'>>>>> Joshua Ulrich <josh.m.ulrich at gmail.com> >>>>> on Wed, 31 Aug 2016 10:35:01 -0500 writes:> I have quantstrat installed and it works fine for me. If you're > asking why the output of t(tradeStats('macross')) isn't being printed, > that's because of what's described in the first paragraph in the > *Details* section of help("source"): > Note that running code via ?source? differs in a few respects from > entering it at the R command line. Since expressions are not > executed at the top level, auto-printing is not done. So you will > need to include explicit ?print? calls for things you want to be > printed (and remember that this includes plotting by ?lattice?, > FAQ Q7.22). > So you need: > print(t(tradeStats('macross'))) > if you want the output printed to the console. indeed, and "of course"" ;-) As my subject indicates, this is another case, where it would be very convenient to have a function withAutoprint() so the OP could have (hopefully) have used withAutoprint(source(..)) though that would have been equivalent to the already nicely existing source(.., print.eval = TRUE) which works via the withVisible(.) utility that returns for each 'expression' if it would auto print or not, and then does print (or not) accordingly. My own use cases for such a withAutoprint({...}) are demos and examples, sometimes even package tests which I want to print: Assume I have a nice demo / example on a help page/ ... foo(..) (z <- bar(..)) summary(z) .... where I carefully do print parts (and don't others), and suddenly I find I want to run that part of the demo / example / test only in some circumstances, e.g., only when interactive, but not in BATCH, or only if it is me, the package maintainer, if( identical(Sys.getenv("USER"), "maechler") ) { foo(..) (z <- bar(..)) summary(z) .... } Now all the auto-printing is gone, and 1) I have to find out which of these function calls do autoprint and wrap a print(..) around these, and 2) the result is quite ugly (for an example on a help page etc.) What I would like in a future R, is to be able to simply wrap the "{ .. } above with an 'withAutoprint(.) : if( identical(Sys.getenv("USER"), "maechler") ) withAutoprint({ foo(..) (z <- bar(..)) summary(z) .... }) Conceptually such a function could be written similar to source() with an R level for loop, treating each expression separately, calling eval(.) etc. That may cost too much performnace, ... still to have it would be better than not having the possibility. ---- If you read so far, you'd probably agree that such a function could be a nice asset in R, notably if it was possible to do this on the fast C level of R's main REPL. Have any of you looked into how this could be provided in R ? If you know the source a little, you will remember that there's the global variable R_Visible which is crucial here. The problem with that is that it *is* global, and only available as that; that the auto-printing "concept" is so linked to "toplevel context" and that is not easy, and AFAIK not so much centralized in one place in the source. Consequently, all kind of (very) low level functions manipulate R_Visible temporarily.... and so a C level implementation of withAutoprint() may need considerable more changes than just setting R_Visible to TRUE in one place. Have any efforts / experiments already happened towards providing such functionality ?