[Blotter-commits] r841 - pkg/FinancialInstrument/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Nov 7 15:41:27 CET 2011


Author: gsee
Date: 2011-11-07 15:41:27 +0100 (Mon, 07 Nov 2011)
New Revision: 841

Modified:
   pkg/FinancialInstrument/R/saveSymbols.R
Log:
 allow for file extensions other than rda

Modified: pkg/FinancialInstrument/R/saveSymbols.R
===================================================================
--- pkg/FinancialInstrument/R/saveSymbols.R	2011-11-06 14:40:25 UTC (rev 840)
+++ pkg/FinancialInstrument/R/saveSymbols.R	2011-11-07 14:41:27 UTC (rev 841)
@@ -25,7 +25,7 @@
 #' @export
 #' @rdname saveSymbols.days
 saveSymbols.days <-
-function(Symbols, base_dir="", env=.GlobalEnv) {
+function(Symbols, base_dir="", extension="rda", env=.GlobalEnv) {
     if (base_dir != "" && 
         !is.null(base_dir) && 
         substr(base_dir,nchar(base_dir),nchar(base_dir)) != "/") 
@@ -38,7 +38,7 @@
             if (!file.exists(paste(base_dir,symbol,sep=""))) dir.create(paste(base_dir,symbol,sep=""))
             fnames <- paste(base_dir,symbol,"/",
                     unlist(lapply(D, FUN=function(x) format(index(first(x)),"%Y.%m.%d"))),
-                    ".", symbol, ".rda", sep="")
+                    ".", symbol, ".", extension, sep="")
             for (i in 1:length(fnames)) {
                 assign(symbol,D[[i]],envir=tmpenv)
                 save(list=symbol,file=fnames[i],envir=tmpenv)
@@ -49,7 +49,7 @@
 
 #' @export
 #' @rdname saveSymbols.days
-saveSymbols.common <- function (Symbols, base_dir = "", env = .GlobalEnv) 
+saveSymbols.common <- function (Symbols, base_dir = "", extension="rda", env = .GlobalEnv) 
 {
     if (base_dir != "" && !is.null(base_dir) && substr(base_dir, 
         nchar(base_dir), nchar(base_dir)) != "/") 
@@ -60,7 +60,7 @@
         if (!is.null(tmp) && !inherits(tmp, "try-error")) {
             if (!file.exists(paste(base_dir, symbol, sep = ""))) 
                 dir.create(paste(base_dir, symbol, sep = ""))
-            fnames <- paste(base_dir, symbol, "/", symbol, ".rda", sep = "")
+            fnames <- paste(base_dir, symbol, "/", symbol, ".", extension, sep = "")
             assign(symbol, tmp, envir = tmpenv)
             save(list = symbol, file = fnames, envir = tmpenv)
         } else if (inherits(tmp, 'try-error')) warning(paste(symbol, "could not be found in 'env' and was not saved."))



More information about the Blotter-commits mailing list