[Blotter-commits] r930 - pkg/FinancialInstrument/R
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Mon Feb 20 05:48:37 CET 2012
Author: gsee
Date: 2012-02-20 05:48:36 +0100 (Mon, 20 Feb 2012)
New Revision: 930
Modified:
pkg/FinancialInstrument/R/update_instruments.yahoo.R
Log:
minor updates to new update_instruments.instrument function
Modified: pkg/FinancialInstrument/R/update_instruments.yahoo.R
===================================================================
--- pkg/FinancialInstrument/R/update_instruments.yahoo.R 2012-02-20 04:21:33 UTC (rev 929)
+++ pkg/FinancialInstrument/R/update_instruments.yahoo.R 2012-02-20 04:48:36 UTC (rev 930)
@@ -229,16 +229,18 @@
#' @export
update_instruments.instrument <- function(Symbols, source_id, create.new=FALSE,
ignore="identifiers", assign_i=TRUE) {
- r <- if (is.instrument(source_id)) { source_id } else getInstrument(source_id)
+ r <- if (is.instrument(source_id)) {
+ source_id
+ } else getInstrument(source_id)
if (!is.instrument(r)) {
stop('source_id is neither an instrument nor the name of an instrument')
}
out <- lapply(Symbols, function(s) {
- si <- getInstrument(s)
+ si <- getInstrument(s, silent=TRUE)
if (!is.instrument(si)) {
warning(paste('could not find instrument"', s, '"Skipping...'))
- next
+ return(NULL)
}
all.empty <- do.call(c, lapply(si, function(x) all(x == "")))
all.empty <- all.empty[!names(all.empty) %in% ignore]
@@ -261,9 +263,11 @@
si
})
if (isTRUE(assign_i)) {
- invisible(lapply(out, function(x) assign(x$primary_id, x,
- pos=FinancialInstrument:::.instrument)))
+ invisible(lapply(out, function(x) {
+ if (!is.null(x)) assign(x$primary_id, x,
+ pos=FinancialInstrument:::.instrument)
+ }))
} else return(out)
- sapply(out, "[[", "primary_id")
+ do.call(c, lapply(out, "[[", "primary_id"))
}
More information about the Blotter-commits
mailing list