[Blotter-commits] r1386 - in pkg/FinancialInstrument: . R inst/tests

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sat Feb 2 22:44:39 CET 2013


Author: gsee
Date: 2013-02-02 22:44:39 +0100 (Sat, 02 Feb 2013)
New Revision: 1386

Added:
   pkg/FinancialInstrument/inst/tests/test-getSymbols.FI.R
Modified:
   pkg/FinancialInstrument/NEWS
   pkg/FinancialInstrument/R/load.instruments.R
Log:
 - if a Symbol was the same as the end of a directory, e.g. "BID" and "/data/BID"
   getSymbols.FI would assume the data are in "/data/BID" instead of "/data/BID/BID".
   I'm not sure why we were doing that; hopefully this doesn't break anything.
 - updated NEWS
 - added regression test



Modified: pkg/FinancialInstrument/NEWS
===================================================================
--- pkg/FinancialInstrument/NEWS	2013-01-28 22:04:22 UTC (rev 1385)
+++ pkg/FinancialInstrument/NEWS	2013-02-02 21:44:39 UTC (rev 1386)
@@ -1,6 +1,12 @@
 Changes in Version 1.2
 ======================
 
+BUG FIXES
+---------
+
+* If the end of dir was the same as Symbol, getSymbols.FI had trouble finding 
+  the files.  Test added.
+
 TESTS
 -----
 

Modified: pkg/FinancialInstrument/R/load.instruments.R
===================================================================
--- pkg/FinancialInstrument/R/load.instruments.R	2013-01-28 22:04:22 UTC (rev 1385)
+++ pkg/FinancialInstrument/R/load.instruments.R	2013-02-02 21:44:39 UTC (rev 1386)
@@ -399,8 +399,7 @@
         Symbol <- ifelse(is.na(instr_str), make.names(Symbols[[i]]), instr_str)
         ndc<-nchar(dir)
         if(substr(dir,ndc,ndc)=='/') dir <- substr(dir,1,ndc-1) #remove trailing forward slash
-        ssd <- strsplit(dir,"/")[[1]]
-        if (identical(character(0), ssd) || (!identical(character(0), ssd) && ssd[length(ssd)] != Symbol)) dir <- paste(dir,Symbol,sep="/")
+        dir <- paste(dir, Symbol, sep="/")
         
         if(!dir=="" && !file.exists(dir)) {
             if (verbose) cat("\ndirectory ",dir," does not exist, skipping\n")

Added: pkg/FinancialInstrument/inst/tests/test-getSymbols.FI.R
===================================================================
--- pkg/FinancialInstrument/inst/tests/test-getSymbols.FI.R	                        (rev 0)
+++ pkg/FinancialInstrument/inst/tests/test-getSymbols.FI.R	2013-02-02 21:44:39 UTC (rev 1386)
@@ -0,0 +1,15 @@
+context("getSymbols.FI")
+
+from <- as.Date('2012-01-01')
+to <- from + 9
+BID <- xts(1:10, as.Date(from:to))
+tmpdir <- file.path(tempdir(), "BID")
+saveSymbols.days("BID", tmpdir, extension="RData")
+rm(BID)
+# make sure getSymbols.FI works if the directory has the same name as the Symbol
+test_that("getSymbols.FI base_dir=Symbol", {
+  expect_identical(NROW(getSymbols("BID", dir=tmpdir, 
+                                   extension="RData", auto.assign=FALSE, 
+                                   from=from, to=to, days_to_omit=NULL,
+                                   verbose=FALSE)), 10L)
+})



More information about the Blotter-commits mailing list