[Blotter-commits] r849 - in pkg/quantstrat: R man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Nov 16 18:47:25 CET 2011


Author: gsee
Date: 2011-11-16 18:47:25 +0100 (Wed, 16 Nov 2011)
New Revision: 849

Modified:
   pkg/quantstrat/R/wrapup.R
   pkg/quantstrat/man/rm.strat.Rd
Log:
 in rm.strat, add silent arg, add example/update docs


Modified: pkg/quantstrat/R/wrapup.R
===================================================================
--- pkg/quantstrat/R/wrapup.R	2011-11-13 17:56:05 UTC (rev 848)
+++ pkg/quantstrat/R/wrapup.R	2011-11-16 17:47:25 UTC (rev 849)
@@ -1,15 +1,35 @@
 #' Remove objects associated with a strategy
 #'
 #' Remove the order_book, account, and portfolio of given \code{name}.
-#' @param name name of the portfolio/account/order book to clean up
+#' @param name name of the portfolio/account/order book to clean up. (Default='default')
+#' @param silent silence warnings about trying to remove objects that do not exist. (Default=TRUE)
+#' @return invisible -- called for side-effect
+#' @examples
+#' \dontrun{
+#' # make some things to remove
+#' strategy("example", store=TRUE)
+#' initPortf('example', stock('SPY', currency("USD")))
+#' initAcct('example', 'example')
+#' initOrders('example', 'SPY')
+#' #Now remove them
+#' rm.strat('example')
+#' }
 #' @export
-rm.strat <- function(name='default') {
+rm.strat <- function(name='default', silent=TRUE) {
     if (is.strategy(name)) name <- name[['name']]
-    try(rm(list=paste("order_book",name,sep="."), pos=.strategy))
-    try(rm(list=paste(c("account", "portfolio"), name, sep="."), pos=.blotter))
+    if (silent) {
+        suppressWarnings({
+            try(rm(list=paste("order_book",name,sep="."), pos=.strategy))
+            try(rm(list=paste(c("account", "portfolio"), name, sep="."), pos=.blotter))
+            try(rm(list=name, pos=.strategy))
+        })
+    } else {
+        try(rm(list=paste("order_book",name,sep="."), pos=.strategy))
+        try(rm(list=paste(c("account", "portfolio"), name, sep="."), pos=.blotter))
+        try(rm(list=name, pos=.strategy))
+    }
 }
 
-
 #' run standard and custom strategy wrapup functions such as updating portfolio, account, and ending equity
 #' 
 #' \code{\link{updateStrategy}} will run a series of common wrapup functions at the 

Modified: pkg/quantstrat/man/rm.strat.Rd
===================================================================
--- pkg/quantstrat/man/rm.strat.Rd	2011-11-13 17:56:05 UTC (rev 848)
+++ pkg/quantstrat/man/rm.strat.Rd	2011-11-16 17:47:25 UTC (rev 849)
@@ -2,14 +2,31 @@
 \alias{rm.strat}
 \title{Remove objects associated with a strategy}
 \usage{
-  rm.strat(name = "default")
+  rm.strat(name = "default", silent = TRUE)
 }
 \arguments{
   \item{name}{name of the portfolio/account/order book to
-  clean up}
+  clean up. (Default='default')}
+
+  \item{silent}{silence warnings about trying to remove
+  objects that do not exist. (Default=TRUE)}
 }
+\value{
+  invisible -- called for side-effect
+}
 \description{
   Remove the order_book, account, and portfolio of given
   \code{name}.
 }
+\examples{
+\dontrun{
+# make some things to remove
+strategy("example", store=TRUE)
+initPortf('example', stock('SPY', currency("USD")))
+initAcct('example', 'example')
+initOrders('example', 'SPY')
+#Now remove them
+rm.strat('example')
+}
+}
 



More information about the Blotter-commits mailing list