[Xts-commits] r821 - in pkg/xtsExtra: R sandbox

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Jul 22 19:35:00 CEST 2014


Author: rossbennett34
Date: 2014-07-22 19:35:00 +0200 (Tue, 22 Jul 2014)
New Revision: 821

Modified:
   pkg/xtsExtra/R/plot2.R
   pkg/xtsExtra/sandbox/test_plot2.R
Log:
Revisions to use FUN instead of mainPanel

Modified: pkg/xtsExtra/R/plot2.R
===================================================================
--- pkg/xtsExtra/R/plot2.R	2014-07-18 21:44:54 UTC (rev 820)
+++ pkg/xtsExtra/R/plot2.R	2014-07-22 17:35:00 UTC (rev 821)
@@ -72,7 +72,7 @@
 }
 
 plot2_xts <- function(x, 
-                      mainPanel=NULL,
+                      FUN=NULL,
                       panels=NULL,
                       byColumn=FALSE,
                       type="l",
@@ -99,13 +99,13 @@
       # we will plot the returns by column, but not the panels
       byColumn <- TRUE
       panels <- NULL
-      mainPanel <- NULL
+      FUN <- NULL
       ylim <- range(na.omit(x[subset]))
     }
     
     for(i in 1:length(chunks)){
       tmp <- chunks[[i]]
-      p <- plot2_xts(x=x[,tmp], mainPanel=mainPanel, panels=panels, 
+      p <- plot2_xts(x=x[,tmp], FUN=FUN, panels=panels, 
                      byColumn=byColumn, type=type, name=name, subset=subset, 
                      clev=clev, pars=pars, theme=theme, ylim=ylim, ...=...)
       if(i < length(chunks))
@@ -213,16 +213,15 @@
   
   # Compute transformation if specified by panel argument
   # rough prototype for calling a function for the main "panel"
-  if(!is.null(mainPanel)){
-    FUN <- match.fun(mainPanel$name)
-    args <- mainPanel$args
-    .formals <- formals(FUN)
-    .formals <- modify.args(formals=.formals, arglist=args, dots=TRUE)
+  if(!is.null(FUN)){
+    fun <- match.fun(FUN)
+    .formals <- formals(fun)
+    .formals <- modify.args(formals=.formals, arglist=list(...), dots=TRUE)
     if("R" %in% names(.formals)) .formals <- modify.args(formals=.formals, arglist=NULL, R=x, dots=TRUE)
     .formals$... <- NULL
-    R <- try(do.call(FUN, .formals), silent=TRUE)
+    R <- try(do.call(fun, .formals), silent=TRUE)
     if(inherits(R, "try-error")) { 
-      message(paste("mainPanel function failed with message", R))
+      message(paste("FUN function failed with message", R))
       cs$Env$R <- x
     } else {
       cs$Env$R <- R

Modified: pkg/xtsExtra/sandbox/test_plot2.R
===================================================================
--- pkg/xtsExtra/sandbox/test_plot2.R	2014-07-18 21:44:54 UTC (rev 820)
+++ pkg/xtsExtra/sandbox/test_plot2.R	2014-07-22 17:35:00 UTC (rev 821)
@@ -34,16 +34,16 @@
 plot2_xts(R, byColumn=TRUE, type="h")
 
 # Replicate charts.PerformanceSummary
-plot2_xts(R, mainPanel=list(name="CumReturns"))
+plot2_xts(R, FUN="CumReturns")
 addReturns(type="h")
 addDrawdowns()
 
 
-plot2_xts(R, mainPanel=list(name="CumReturns"),
+plot2_xts(R, FUN="CumReturns",
           panels=c("addReturns(type='h')", "addDrawdowns()"))
 
 layout(matrix(1:4, 2, 2))
-plot2_xts(R, byColumn=1, mainPanel=list(name="CumReturns"),
+plot2_xts(R, byColumn=1, FUN="CumReturns",
           panels=c("addReturns(type='h')", "addDrawdowns()"))
 layout(matrix(1))
 
@@ -51,7 +51,7 @@
 # y-axis range here can be deceiving
 layout(matrix(1:4, 2, 2))
 for(i in 1:ncol(R)){
-  p <- plot2_xts(R[,i], mainPanel=list(name="CumReturns"),
+  p <- plot2_xts(R[,i], FUN="CumReturns",
                  panels=c("addReturns(type='h')", "addDrawdowns()"),
                  name=colnames(R)[i])
   print(p)
@@ -70,7 +70,8 @@
 layout(matrix(1))
 
 # Rolling performance
-plot2_xts(R, mainPanel=list(name="CumReturns"))
+plot2_xts(R, FUN="CumReturns", geometric=FALSE)
+plot2_xts(R, FUN="CumReturns", geometric=TRUE, wealth.index=TRUE)
 addRollingPerformance()
 addRollingPerformance(FUN="StdDev.annualized")
 addRollingPerformance(FUN="SharpeRatio.annualized")



More information about the Xts-commits mailing list