[Blotter-commits] r1549 - pkg/blotter/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Oct 24 14:34:33 CEST 2013


Author: bodanker
Date: 2013-10-24 14:34:33 +0200 (Thu, 24 Oct 2013)
New Revision: 1549

Modified:
   pkg/blotter/R/getPortfolio.R
Log:
- handle case where portfolio may already be a list
- add class, currency, and initDate attributes


Modified: pkg/blotter/R/getPortfolio.R
===================================================================
--- pkg/blotter/R/getPortfolio.R	2013-10-24 09:30:51 UTC (rev 1548)
+++ pkg/blotter/R/getPortfolio.R	2013-10-24 12:34:33 UTC (rev 1549)
@@ -23,9 +23,15 @@
 { 
   pname<-Portfolio
   oport<- .getPortfolio(Portfolio, envir=envir)
-  port <- as.list.environment(oport)
-  port$symbols<-list()
-  port$symbols <- lapply(oport$symbols, as.list.environment)
+  if(is.environment(oport))
+      port <- as.list.environment(oport)
+  else
+      port <- oport
+  port$symbols <- lapply(oport$symbols, function(s) if(is.environment(s)) as.list.environment(s) else s)
+
+  class(port) <- class(oport)
+  attr(port, "currency") <- attr(oport, "currency")
+  attr(port, "initDate") <- attr(oport, "initDate")
   
   if(!is.null(Dates)){
     message("date subsetting not yet supported")



More information about the Blotter-commits mailing list