nesvarbu
nesvarbu

Reputation: 1016

Using addPosLimit and osMaxPos throws "error in PosLimit[, "MaxPos"] : incorrect number of dimensions"

Even if I copy paste example from blog.fosstrading.com/2011/08/tactical-asset-allocation-using.html I get this error:

 error in PosLimit[, "MaxPos"] : incorrect number of dimensions

Is this a bug or am I missing something?

Output from sessionInfo():

R version 3.2.2 (2015-08-14)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] dplyr_0.4.3                   quantstrat_0.9.1687           foreach_1.4.2                
 [4] blotter_0.9.1695              PerformanceAnalytics_1.4.3662 FinancialInstrument_1.2.0    
 [7] quantmod_0.4-5                TTR_0.23-0                    xts_0.9-7                    
[10] zoo_1.7-12                   

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.1      lattice_0.20-33  codetools_0.2-14 assertthat_0.1   grid_3.2.2      
 [6] R6_2.1.1         DBI_0.3.1        magrittr_1.5     iterators_1.0.7  tools_3.2.2     
[11] parallel_3.2.2  

Upvotes: 1

Views: 139

Answers (1)

Joshua Ulrich
Joshua Ulrich

Reputation: 176648

You have dplyr loaded. It defines a lag function that masks the generic function, stats::lag. dplyr::lag does not do any method dispatch, so there's a lag method somewhere that isn't being called when it should be.

dplyr also masks the first and last generics defined in xts, which may also cause problems.

A short-term work-around is to call library(dplyr) first, so first and last in xts will mask their couterparts in dplyr. The long-term solution is that all packages should explicitly import all functions they use to avoid issues caused by the sequence in which packages are loaded/attached (note that user's non-packaged code will still be affected by package load/attach order).

Upvotes: 3

Related Questions