[R] source() does not include added code

Joshua Ulrich josh.m.ulrich at gmail.com
Wed Aug 31 17:35:01 CEST 2016


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
> 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.



-- 
Joshua Ulrich  |  about.me/joshuaulrich
FOSS Trading  |  www.fosstrading.com
R/Finance 2016 | www.rinfinance.com



More information about the R-help mailing list