[Blotter-commits] r900 - in pkg/FinancialInstrument: . R man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Jan 2 23:27:20 CET 2012


Author: gsee
Date: 2012-01-02 23:27:16 +0100 (Mon, 02 Jan 2012)
New Revision: 900

Modified:
   pkg/FinancialInstrument/DESCRIPTION
   pkg/FinancialInstrument/R/instrument.R
   pkg/FinancialInstrument/R/load.instruments.R
   pkg/FinancialInstrument/man/getSymbols.FI.Rd
   pkg/FinancialInstrument/man/instrument_attr.Rd
Log:
revert to using SymbolLookup table; getSymbols.FI now choose the correct value for its args

Modified: pkg/FinancialInstrument/DESCRIPTION
===================================================================
--- pkg/FinancialInstrument/DESCRIPTION	2012-01-01 19:00:09 UTC (rev 899)
+++ pkg/FinancialInstrument/DESCRIPTION	2012-01-02 22:27:16 UTC (rev 900)
@@ -11,7 +11,7 @@
     meta-data and relationships. Provides support for
     multi-asset class and multi-currency portfolios. Still
     in heavy development.
-Version: 0.10.0
+Version: 0.10.1
 URL: https://r-forge.r-project.org/projects/blotter/
 Date: $Date$
 Depends:

Modified: pkg/FinancialInstrument/R/instrument.R
===================================================================
--- pkg/FinancialInstrument/R/instrument.R	2012-01-01 19:00:09 UTC (rev 899)
+++ pkg/FinancialInstrument/R/instrument.R	2012-01-02 22:27:16 UTC (rev 900)
@@ -135,7 +135,6 @@
   if (raw_id != primary_id) {
       identifiers <- c(identifiers, raw_id=raw_id)
   }
-
   arg<-list(...)
   if(is.list(arg[['...']])){
       if(length(arg)==1) arg <- arg[['...']]
@@ -146,30 +145,8 @@
       }
   }
   if (!is.null(arg$src)) {
-      # Clear out anything stored in SymbolLookupTable for this instrument
-      eval(parse(text=paste('setSymbolLookup(', primary_id, '=', 'NULL', ')', sep="")))
-
       sarg <- list()
-      if (length(arg$src) == 1) {
-          sarg[[primary_id]] <- arg$src
-      }  else {
-          #FIXME: @quantmod developers: getSymbols should not have a "verbose" argument.
-          # The 'verbose' arg belongs in the methods because the user may want to verbose=TRUE
-          # for some getSymbols methods, but verbose=FALSE for other ones. For now, I will
-          # store the "verbose" value in the SymbolLookup table so that the user can set different
-          # defaults for different methods, but that means that local args will be ignored.
-          # i.e. if you call stock("SPY", currency("USD"), src=list(src='FI', verbose=TRUE)), then
-          # if you call getSymbols("SPY", verbose=FALSE), it will use verbose=TRUE.
-          sarg[[primary_id]] <- if (is.null(arg$src$verbose)) {
-              arg$src$src
-          } else {
-              arg$src[c('src', 'verbose')]
-          }
-          tmparg <- arg
-          tmparg$src$src <- NULL
-          #tmparg$src$verbose <- NULL #make NULL if we decide to only use verbose arg of getSymbols
-          do.call(setDefaults, c("getSymbols.FI", tmparg$src))
-      }
+      sarg[[primary_id]] <- arg$src
       setSymbolLookup(sarg)
       #arg[["src"]]<-NULL
   }
@@ -990,9 +967,7 @@
 #' If the \code{attr} you are trying to change is the \dQuote{primary_id,} the instrument will be renamed.
 #' (A copy of the instrument will be stored by the name of \code{value} and the old instrument will be removed.)
 #' If the \code{attr} you are changing is \dQuote{type}, the instrument will be reclassed with that type.
-#' If \code{attr} is \dQuote{src}, \code{value} will be used in a call to \code{setSymbolLookup}.  If \dQuote{src}
-#' is a list with more than 1 item, \code{setSymbolLookup} will be called with the item named \sQuote{src}, and
-#' the remaining items will be passed used in a call to \code{setDefaults} along with \code{.name='getSymbols.FI'}
+#' If \code{attr} is \dQuote{src}, \code{value} will be used in a call to \code{setSymbolLookup}.  
 #' Other checks are in place to make sure that \dQuote{currency} remains a \code{\link{currency}} object and that
 #' \dQuote{multiplier} and \dQuote{tick_size} can only be changed to reasonable values.
 #' @param primary_id primary_id of the instrument that will be updated
@@ -1045,32 +1020,10 @@
         }
     }
     if (attr == 'src') {
-      # Clear out anything stored in SymbolLookupTable
-      eval(parse(text=paste('setSymbolLookup(', primary_id, '=', 'NULL', ')', sep="")))
-      sarg <- list()
-      if (length(value) == 1) {
-          sarg[[primary_id]] <- value
-      }  else {
-          #FIXME: @quantmod developers: getSymbols should not have a "verbose" argument.
-          # The 'verbose' arg belongs in the methods because the user may want to verbose=TRUE
-          # for some getSymbols methods, but verbose=FALSE for other ones. For now, I will
-          # store the "verbose" value in the SymbolLookup table so that the user can set different
-          # defaults for different methods, but that means that local args will be ignored.
-          # i.e. if you call instrument_attr("SPY", "src", list(src='FI', verbose=TRUE)), then
-          # if you call getSymbols("SPY", verbose=FALSE), it will use verbose=TRUE.
-          sarg[[primary_id]] <- if (is.null(value$verbose)) {
-              value$src
-          } else {
-              value[c('src', 'verbose')]
-          }
-          value$src <- NULL
-          #value$verbose <- NULL
-          do.call(setDefaults, c("getSymbols.FI", value))
-      }
-      setSymbolLookup(sarg)
-      #arg[["src"]]<-NULL
-  }
-
+        sarg <- list()
+        sarg[[instr$primary_id]] <- value
+        setSymbolLookup(sarg)
+    }
     assign(instr$primary_id, instr, pos=FinancialInstrument:::.instrument)
 }
 

Modified: pkg/FinancialInstrument/R/load.instruments.R
===================================================================
--- pkg/FinancialInstrument/R/load.instruments.R	2012-01-01 19:00:09 UTC (rev 899)
+++ pkg/FinancialInstrument/R/load.instruments.R	2012-01-02 22:27:16 UTC (rev 900)
@@ -259,11 +259,6 @@
 #' However, if you were to call \code{getSymbols.FI} directly (which is \emph{NOT} recommended) 
 #' with \code{auto.assign=FALSE} and more than one Symbol, a list would be returned.
 #' 
-#' @note getSymbols and getSymbols.FI both have a \code{verbose} argument.  If a value has been
-#' set for \code{verbose} in the SymbolLookup table, it will be used in spite of any local args.
-#' If you want to change it, you will have to change it with a call to \code{instrument_attr} 
-#' or \code{setSymbolLookup}.  If you call either of those with \code{verbose=NULL}, the \code{verbose}
-#' arg will be unset and local arguments will again be respected.
 #' @param Symbols a character vector specifying the names of each symbol to be loaded
 #' @param from Retrieve data no earlier than this date. Default '2010-01-01'.
 #' @param to Retrieve data through this date. Default Sys.Date().
@@ -309,7 +304,7 @@
     }
 
     #The body of the following function comes from Dominik's answer here: 
-    #browseURL{"http://stackoverflow.com/questions/7224938/can-i-rbind-be-parallelized-in-r"}
+    #browseURL("http://stackoverflow.com/questions/7224938/can-i-rbind-be-parallelized-in-r")
     #it does what do.call(rbind, lst) would do, but faster and with less memory usage
     do.call.rbind <- function(lst) {
         while(length(lst) > 1) {
@@ -324,7 +319,21 @@
         lst[[1]]
     }
 
-    default.from <- from    
+    # Find out if user provided a value for each formal
+    hasArg.from <- hasArg(from)
+    hasArg.to <- hasArg(to)
+    hasArg.dir <- hasArg(dir)
+    hasArg.return.class <- hasArg(return.class)
+    hasArg.extension <- hasArg(extension)
+    hasArg.split_method <- hasArg(split_method)
+    hasArg.use_identifier <- hasArg(use_identifier)
+    hasArg.date_format <- hasArg(date_format)
+    hasArg.verbose <- hasArg(verbose)
+    hasArg.days_to_omit <- hasArg(days_to_omit)
+
+    # Now get the values for each formal that we'll use if not provided
+    # by the user and not found in the SymbolLookup table
+    default.from <- from
     default.to <- to
     default.dir <- dir
     default.return.class <- return.class
@@ -338,29 +347,29 @@
     # so the next 2 if statements should always be TRUE
     auto.assign <- if(hasArg(auto.assign)) {auto.assign} else TRUE
     env <- if(hasArg(env)) {env} else .GlobalEnv 
+
+    # make an argument matching function to sort out which values to use for each arg
+    pickArg <- function(x, Symbol) {
+        if(get(paste('hasArg', x, sep="."))) {
+            get(x)
+        } else if(!is.null(SymbolLookup[[Symbol]][[x]])) {
+            SymbolLookup[[Symbol]][[x]]
+        } else get(paste("default", x, sep="."))
+    }
+
+    SymbolLookup <- getSymbolLookup()
     fr <- NULL
     datl <- lapply(1:length(Symbols), function(i) {
-        from <- getSymbolLookup()[[Symbols[[i]]]]$from 
-        from <- if(is.null(from)) { default.from } else from
-        to <- getSymbolLookup()[[Symbols[[i]]]]$to
-        to <- if(is.null(to)) { default.to } else to
-        dir <- getSymbolLookup()[[Symbols[[i]]]]$dir
-        dir <- if(is.null(dir)) { default.dir } else dir
-        return.class <- getSymbolLookup()[[Symbols[[i]]]]$return.class
-        return.class <- if(is.null(return.class)) { default.return.class } else return.class
-        extension <- getSymbolLookup()[[Symbols[[i]]]]$extension
-        extension <- if (is.null(extension)) { default.extension } else extension
-        split_method <- getSymbolLookup()[[Symbols[[i]]]]$split_method
-        split_method <- if (is.null(split_method)) { default.split_method } else split_method
-        use_identifier <- getSymbolLookup()[[Symbols[[i]]]]$use_identifier
-        use_identifier <- if (is.null(use_identifier)) { default.use_identifier } else use_identifier
-        date_format <- getSymbolLookup()[[Symbols[[i]]]]$date_format
-        date_format <- if(is.null(date_format)) { default.date_format } else date_format
-        verbose <- getSymbolLookup()[[Symbols[[i]]]]$verbose
-        verbose <- if(is.null(verbose)) { default.verbose } else verbose
-        days_to_omit <- getSymbolLookup()[[Symbols[[i]]]]$days_to_omit
-        days_to_omit <- if(is.null(days_to_omit)) { default.days_to_omit } else days_to_omit
-
+        from <- pickArg("from", Symbols[[i]])
+        to <- pickArg("to", Symbols[[i]])
+        dir <- pickArg("dir", Symbols[[i]])
+        return.class <- pickArg("return.class", Symbols[[i]])
+        extension <- pickArg('extension', Symbols[[i]])
+        split_method <- pickArg('split_method', Symbols[[i]])
+        use_identifier <- pickArg('use_identifier', Symbols[[i]])
+        date_format <- pickArg('date_format', Symbols[[i]])
+        verbose <- pickArg('verbose', Symbols[[i]])
+        days_to_omit <- pickArg('days_to_omit', Symbols[[i]])
         # if 'dir' is actually the 'base_dir' then we'll paste the instrument name (Symbol) to the end of it.
         # First, find out what the instrument name is
         instr_str <- NA

Modified: pkg/FinancialInstrument/man/getSymbols.FI.Rd
===================================================================
--- pkg/FinancialInstrument/man/getSymbols.FI.Rd	2012-01-01 19:00:09 UTC (rev 899)
+++ pkg/FinancialInstrument/man/getSymbols.FI.Rd	2012-01-02 22:27:16 UTC (rev 900)
@@ -70,16 +70,6 @@
   is \emph{NOT} recommended) with \code{auto.assign=FALSE}
   and more than one Symbol, a list would be returned.
 }
-\note{
-  getSymbols and getSymbols.FI both have a \code{verbose}
-  argument.  If a value has been set for \code{verbose} in
-  the SymbolLookup table, it will be used in spite of any
-  local args. If you want to change it, you will have to
-  change it with a call to \code{instrument_attr} or
-  \code{setSymbolLookup}.  If you call either of those with
-  \code{verbose=NULL}, the \code{verbose} arg will be unset
-  and local arguments will again be respected.
-}
 \seealso{
   \code{\link{saveSymbols.days}} \code{\link{instrument}}
   \code{\link{setSymbolLookup.FI}}

Modified: pkg/FinancialInstrument/man/instrument_attr.Rd
===================================================================
--- pkg/FinancialInstrument/man/instrument_attr.Rd	2012-01-01 19:00:09 UTC (rev 899)
+++ pkg/FinancialInstrument/man/instrument_attr.Rd	2012-01-02 22:27:16 UTC (rev 900)
@@ -29,13 +29,8 @@
   the \code{attr} you are changing is \dQuote{type}, the
   instrument will be reclassed with that type. If
   \code{attr} is \dQuote{src}, \code{value} will be used in
-  a call to \code{setSymbolLookup}.  If \dQuote{src} is a
-  list with more than 1 item, \code{setSymbolLookup} will
-  be called with the item named \sQuote{src}, and the
-  remaining items will be passed used in a call to
-  \code{setDefaults} along with
-  \code{.name='getSymbols.FI'} Other checks are in place to
-  make sure that \dQuote{currency} remains a
+  a call to \code{setSymbolLookup}. Other checks are in
+  place to make sure that \dQuote{currency} remains a
   \code{\link{currency}} object and that
   \dQuote{multiplier} and \dQuote{tick_size} can only be
   changed to reasonable values.



More information about the Blotter-commits mailing list