[Blotter-commits] r979 - in pkg/FinancialInstrument: . R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sat Mar 24 04:23:47 CET 2012
Author: gsee
Date: 2012-03-24 04:23:46 +0100 (Sat, 24 Mar 2012)
New Revision: 979
Modified:
pkg/FinancialInstrument/DESCRIPTION
pkg/FinancialInstrument/R/instrument.R
pkg/FinancialInstrument/man/add.identifier.Rd
Log:
rewrite of add.instrument
Modified: pkg/FinancialInstrument/DESCRIPTION
===================================================================
--- pkg/FinancialInstrument/DESCRIPTION 2012-03-24 00:53:23 UTC (rev 978)
+++ pkg/FinancialInstrument/DESCRIPTION 2012-03-24 03:23:46 UTC (rev 979)
@@ -11,7 +11,7 @@
meta-data and relationships. Provides support for
multi-asset class and multi-currency portfolios. Still
in heavy development.
-Version: 0.13.2
+Version: 0.13.3
URL: https://r-forge.r-project.org/projects/blotter/
Date: $Date$
Depends:
Modified: pkg/FinancialInstrument/R/instrument.R
===================================================================
--- pkg/FinancialInstrument/R/instrument.R 2012-03-24 00:53:23 UTC (rev 978)
+++ pkg/FinancialInstrument/R/instrument.R 2012-03-24 03:23:46 UTC (rev 979)
@@ -1083,12 +1083,13 @@
assign(instr$primary_id, instr, pos=FinancialInstrument:::.instrument)
}
-
+
#' add an identifier to an \code{instrument}
+#'
+#' Add an identifier to an \code{\link{instrument}} unless the instrument
+#' already has that identifier.
#' @param primary_id primary_id of an \code{\link{instrument}}
-#' @param identifier the identifier to add. Either a list, or a string that
-#' will be coerced to a list.
-#' @param ... parameters to pass through to \code{\link{getInstrument}}
+#' @param ... identifiers passed as regular named arguments.
#' @return called for side-effect
#' @author Garrett See
#' @seealso \code{\link{instrument_attr}}
@@ -1101,14 +1102,22 @@
#' all.equal(getInstrument("x3"), getInstrument("XXX")) #TRUE
#' }
#' @export
-add.identifier <- function(primary_id, identifier, ...) {
- ident <- getInstrument(primary_id, ...)[["identifiers"]]
- if (!is.list(identifier)) identifier <- as.list(identifier)
- instrument_attr(primary_id, "identifiers", c(ident, identifier))
+add.identifier <- function(primary_id, ...) {
+ udots <- unlist(...)
+ new.ids <- list(udots)
+ names(new.ids) <- names(udots)
+ instr <- getInstrument(primary_id)
+ if (!inherits(instr, "instrument")) {
+ stop(paste(primary_id, "is not a defined instrument"))
+ }
+ ids <- c(instr[["identifiers"]], new.ids)
+ if (all(is.null(names(ids)))) {
+ instrument_attr(primary_id, "identifiers", unique(ids))
+ } else instrument_attr(primary_id, "identifiers",
+ ids[!(duplicated(unlist(ids)) & duplicated(names(ids)))])
}
-
-
+
#' instrument class print method
#'
#' @method print instrument
Modified: pkg/FinancialInstrument/man/add.identifier.Rd
===================================================================
--- pkg/FinancialInstrument/man/add.identifier.Rd 2012-03-24 00:53:23 UTC (rev 978)
+++ pkg/FinancialInstrument/man/add.identifier.Rd 2012-03-24 03:23:46 UTC (rev 979)
@@ -2,23 +2,21 @@
\alias{add.identifier}
\title{add an identifier to an \code{instrument}}
\usage{
- add.identifier(primary_id, identifier, ...)
+ add.identifier(primary_id, ...)
}
\arguments{
\item{primary_id}{primary_id of an
\code{\link{instrument}}}
- \item{identifier}{the identifier to add. Either a list,
- or a string that will be coerced to a list.}
-
- \item{...}{parameters to pass through to
- \code{\link{getInstrument}}}
+ \item{...}{identifiers passed as regular named
+ arguments.}
}
\value{
called for side-effect
}
\description{
- add an identifier to an \code{instrument}
+ Add an identifier to an \code{\link{instrument}} unless
+ the instrument already has that identifier.
}
\examples{
\dontrun{
More information about the Blotter-commits
mailing list