[Blotter-commits] r968 - in pkg/FinancialInstrument: R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Thu Mar 8 04:28:31 CET 2012
Author: gsee
Date: 2012-03-08 04:28:31 +0100 (Thu, 08 Mar 2012)
New Revision: 968
Added:
pkg/FinancialInstrument/man/find.instrument.Rd
Modified:
pkg/FinancialInstrument/R/find.instrument.R
Log:
- add "exclude" arg to find.instrument
- add docs
Modified: pkg/FinancialInstrument/R/find.instrument.R
===================================================================
--- pkg/FinancialInstrument/R/find.instrument.R 2012-03-08 02:39:22 UTC (rev 967)
+++ pkg/FinancialInstrument/R/find.instrument.R 2012-03-08 03:28:31 UTC (rev 968)
@@ -28,6 +28,8 @@
#' @param ignore.case passed to \code{\link{grep}}; if \code{FALSE}, the pattern
#' matching is case sensitive and if \code{TRUE}, case is ignored during
#' matching.
+#' @param exclude character vector of names of levels/attributes that should not
+#' be searched.
#' @param ... other arguments to pass throught to \code{\link{grep}}
#' @return character vector of primary_ids of instruments that contain the
#' sought after \code{text}.
@@ -56,10 +58,10 @@
#' }
#' @export
find.instrument <- function(text, where='anywhere', Symbols = ls_instruments(),
- ignore.case=TRUE, ...) {
+ ignore.case=TRUE, exclude=NULL, ...) {
tbl <- if (where == "anywhere") {
- instrument.table(Symbols)
- } else buildHierarchy(Symbols, where)
+ instrument.table(Symbols, exclude=exclude)
+ } else buildHierarchy(Symbols, where[!where %in% exclude])
tbl[unique(unname(unlist(apply(tbl, 2, function(x)
grep(pattern=text, x=x, ignore.case=ignore.case, ...))))), 1]
}
Added: pkg/FinancialInstrument/man/find.instrument.Rd
===================================================================
--- pkg/FinancialInstrument/man/find.instrument.Rd (rev 0)
+++ pkg/FinancialInstrument/man/find.instrument.Rd 2012-03-08 03:28:31 UTC (rev 968)
@@ -0,0 +1,69 @@
+\name{find.instrument}
+\alias{find.instrument}
+\title{Find the primary_ids of instruments that contain certain
+strings}
+\usage{
+ find.instrument(text, where = "anywhere",
+ Symbols = ls_instruments(), ignore.case = TRUE,
+ exclude = NULL, ...)
+}
+\arguments{
+ \item{text}{string to search for}
+
+ \item{where}{if \dQuote{anywhere} all levels/attributes
+ of the instruments will be searched. Otherwise,
+ \code{where} can be used to specify in which
+ levels/attributes to look. (e.g. \code{c("name",
+ "description")} would only look for \code{text} in those
+ 2 places.}
+
+ \item{Symbols}{the character ids of instruments to be
+ searched. All are are searched by default.}
+
+ \item{ignore.case}{passed to \code{\link{grep}}; if
+ \code{FALSE}, the pattern matching is case sensitive and
+ if \code{TRUE}, case is ignored during matching.}
+
+ \item{exclude}{character vector of names of
+ levels/attributes that should not be searched.}
+
+ \item{...}{other arguments to pass throught to
+ \code{\link{grep}}}
+}
+\value{
+ character vector of primary_ids of instruments that
+ contain the sought after \code{text}.
+}
+\description{
+ Uses regular expressions matching to find
+ \code{\link{instrument}}s
+}
+\examples{
+\dontrun{
+instruments.bak <- as.list(FinancialInstrument:::.instrument)
+rm_instruments(keep.currencies=FALSE)
+currency("USD")
+stock("SPY", "USD", description="S&P 500 ETF")
+stock("DIA", "USD", description="DJIA ETF")
+stock(c("AA", "AXP", "BA", "BAC", "CAT"), "USD", members.of='DJIA')
+stock("BMW", currency("EUR"))
+find.instrument("ETF")
+find.instrument("DJIA")
+find.instrument("DJIA", "members.of")
+find.instrument("USD")
+find.instrument("EUR")
+find.instrument("EUR", Symbols=ls_stocks())
+find.instrument("USD", "type")
+## Cleanup. restore previous instrument environment
+rm_instruments(); rm_currencies()
+loadInstruments(instruments.bak)
+}
+}
+\author{
+ Garrett See
+}
+\seealso{
+ \code{\link{buildHierarchy}},
+ \code{\link{instrument.table}}, \code{\link{regex}}
+}
+
More information about the Blotter-commits
mailing list