[Quantmod-commits] r597 - in pkg: . R man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Jan 4 07:40:30 CET 2013


Author: jryan
Date: 2013-01-04 07:40:30 +0100 (Fri, 04 Jan 2013)
New Revision: 597

Modified:
   pkg/CHANGES
   pkg/R/getDividends.R
   pkg/R/getFinancials.R
   pkg/R/getSplits.R
   pkg/R/getSymbols.R
   pkg/man/getSymbols.Rd
Log:
o  added env=NULL ability to all other get* functions (same behavior as auto.assign=FALSE)
o  new CHANGES updates to reflect current and forthcoming (0.5-0) changes to get/loadSymbols
o  additional getSymbols.Rd updates/example changes


Modified: pkg/CHANGES
===================================================================
--- pkg/CHANGES	2013-01-02 03:15:26 UTC (rev 596)
+++ pkg/CHANGES	2013-01-04 06:40:30 UTC (rev 597)
@@ -1,3 +1,20 @@
+0.4-0
+MAJOR CHANGES
+
+- getSymbols now uses parent.frame() when auto.assign=TRUE. This
+  will cause slightly different behavior than previous versions
+  using .GlobalEnv, but is more functional in design.
+
+- getSymbols now allows for env=NULL, which will behave
+  as if auto.assign=FALSE is set.
+
+- Upcoming changes for version 0.5-0 will include deprecating
+  auto assignment from within getSymbols calls. This will instead
+  be moved to the loadSymbols function, to better match get/load
+  behaviors in base R.  For the transition, auto.assign will be
+  available to force pre 0.5-0 behaviors, but will be discouraged.
+  The env= arg will be used for multiple symbol assigns.
+
 0.3-7
 - addTA now handles logical vectors or logical xtsible objects
   by drawing bands on chart window

Modified: pkg/R/getDividends.R
===================================================================
--- pkg/R/getDividends.R	2013-01-02 03:15:26 UTC (rev 596)
+++ pkg/R/getDividends.R	2013-01-04 06:40:30 UTC (rev 597)
@@ -2,6 +2,10 @@
 function(Symbol,from='1970-01-01',to=Sys.Date(),env=parent.frame(),src='yahoo',
          auto.assign=FALSE,auto.update=FALSE,verbose=FALSE,...) {
 
+  if(missing(env))
+    env <- parent.frame(1)
+  if(is.null(env))
+    auto.assign <- FALSE
   Symbol.name <- ifelse(!is.character(Symbol),
                         deparse(substitute(Symbol)),
                         as.character(Symbol))

Modified: pkg/R/getFinancials.R
===================================================================
--- pkg/R/getFinancials.R	2013-01-02 03:15:26 UTC (rev 596)
+++ pkg/R/getFinancials.R	2013-01-04 06:40:30 UTC (rev 597)
@@ -1,4 +1,8 @@
 getFin <- function(Symbol, env=parent.frame(), src="google", auto.assign=TRUE, ...) {
+  if(missing(env))
+    env <- parent.frame(1)
+  if(is.null(env))
+    auto.assign <- FALSE
   Symbol <- strsplit(Symbol,";")[[1]]
   if(length(Symbol)>1)
     return(unlist(lapply(Symbol, getFin, env=env, src=src, auto.assign=auto.assign)))

Modified: pkg/R/getSplits.R
===================================================================
--- pkg/R/getSplits.R	2013-01-02 03:15:26 UTC (rev 596)
+++ pkg/R/getSplits.R	2013-01-04 06:40:30 UTC (rev 597)
@@ -4,6 +4,10 @@
 
   # Function written by Joshua Ulrich, using
   # getSymbols.yahoo as a guide.
+  if(missing(env))
+    env <- parent.frame(1)
+  if(is.null(env))
+    auto.assign <- FALSE
   Symbol.name <- ifelse(!is.character(Symbol),
                         deparse(substitute(Symbol)),
                         as.character(Symbol))

Modified: pkg/R/getSymbols.R
===================================================================
--- pkg/R/getSymbols.R	2013-01-02 03:15:26 UTC (rev 596)
+++ pkg/R/getSymbols.R	2013-01-04 06:40:30 UTC (rev 597)
@@ -1,7 +1,8 @@
 # getSymbols {{{
 "getSymbols" <-
 function(Symbols=NULL,
-         env=parent.frame(),
+         env=parent.frame(),  ### 0.4-0
+         #env=NULL,          ### 0.5-0
          reload.Symbols=FALSE,
          verbose=FALSE,
          warnings=TRUE,
@@ -13,11 +14,30 @@
         # transition message for 0.4-0 to 0.5-0
         message(paste('    As of 0.4-0,',sQuote('getSymbols'),'uses env=parent.frame() by default.\n',
                 'This behavior will be phased out in 0.5-0 when the call will check\n',
-                'getOptions("getSymbols")$env for default value. If NULL, auto.assign will\n',
-                'be set to FALSE.  This message is only shown once per session.'))
+                'getOption("getSymbols")$env for default value. If NULL, auto.assign will\n',
+                'be set to FALSE.  This message is only shown once per session.',
+                '\nSee ?quantmodNEWS for more.'))
         .quantmodEnv$options$newEnvmessage <- TRUE 
       }
+      getSymbols_options_ <- function(option) {
+        gso <- getOption("getSymbols")
+        if(is.list(gso))
+          gso[[option]]
+        else NULL
+      }
       importDefaults("getSymbols")
+      #  to enable as-it-was behavior, set this:
+      #  options(getSymbols=list(env=substitute(parent.frame(3))))
+
+      #if(missing(env))
+      #  env <- eval(getOption("getSymbols")$env)    ### 0.5-0
+
+      if(missing(env))
+        env <- parent.frame(1)                      ### 0.4-0
+
+      #env_ <- getSymbols_options_("env")
+      #if(missing(env) && !is.null(env_))
+      #  env <- env_
       if(is.null(env)) # default as of 0.5-0
         auto.assign <- FALSE
       if(!auto.assign && length(Symbols)>1)
@@ -532,6 +552,10 @@
          verbose=FALSE,warning=TRUE,
          auto.assign=TRUE,...) {
   importDefaults("getFX")
+  if(missing(env))
+    env <- parent.frame(1)
+  if(is.null(env))
+    auto.assign <- FALSE
   if(!auto.assign && length(Currencies) > 1)
     stop("must use auto.assign=TRUE for multiple currency requests")
   #src <- c('oanda','FRED')[pmatch(src,c('oanda','FRED'))[1]]
@@ -558,6 +582,10 @@
          verbose=FALSE,warning=TRUE,
          auto.assign=TRUE,...) {
   importDefaults("getMetals")
+  if(missing(env))
+    env <- parent.frame(1)
+  if(is.null(env))
+    auto.assign <- FALSE
   metals <- c("XAU-GOLD","XPD-PALLADIUM","XPT-PLATINUM","XAG-SILVER")
   metals <- metals[sapply(Metals, function(x) grep(x,metals,ignore.case=TRUE))]
   metals <- as.character(sapply(metals,

Modified: pkg/man/getSymbols.Rd
===================================================================
--- pkg/man/getSymbols.Rd	2013-01-02 03:15:26 UTC (rev 596)
+++ pkg/man/getSymbols.Rd	2013-01-04 06:40:30 UTC (rev 597)
@@ -208,7 +208,7 @@
 
 # constrain to local scope
 local( {
-  getSymbols("AAPL")
+  getSymbols("AAPL")  # or getSymbols("AAPL", env=environment())
   str(AAPL)
   })
 
@@ -218,6 +218,7 @@
 attach(NULL, name="DATA.ENV")
 getSymbols("AAPL", env=as.environment("DATA.ENV"))
 ls("DATA.ENV")
+detach("DATA.ENV")
 
 # directly return to caller
 str( getSymbols("AAPL", env=NULL) )



More information about the Quantmod-commits mailing list