[Pomp-commits] r449 - in pkg: R man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue May 3 16:52:20 CEST 2011


Author: kingaa
Date: 2011-05-03 16:52:19 +0200 (Tue, 03 May 2011)
New Revision: 449

Modified:
   pkg/R/bsplines.R
   pkg/man/bsplines.Rd
Log:
- add 'names' argument


Modified: pkg/R/bsplines.R
===================================================================
--- pkg/R/bsplines.R	2011-04-27 14:59:10 UTC (rev 448)
+++ pkg/R/bsplines.R	2011-05-03 14:52:19 UTC (rev 449)
@@ -1,5 +1,33 @@
-bspline.basis <- function (x, nbasis, degree = 3)
-  .Call(bspline_basis,x,nbasis,degree)
+bspline.basis <- function (x, nbasis, degree = 3, names = NULL) {
+  y <- .Call(bspline_basis,x,nbasis,degree)
+  if (!is.null(names)) {
+    if (length(names)==1) {
+      nm <- sprintf(names,seq_len(nbasis))
+      if (length(unique(nm))!=nbasis)
+        nm <- paste(names,seq_len(nbasis),sep=".")
+      colnames(y) <- nm 
+    } else if (length(names)==nbasis) {
+      colnames(y) <- names
+    } else {
+      stop(sQuote("length(names)")," must be either 1 or ",nbasis)
+    }
+  }
+  y
+}
 
-periodic.bspline.basis <- function (x, nbasis, degree = 3, period = 1)
-  .Call(periodic_bspline_basis,x,nbasis,degree,period)
+periodic.bspline.basis <- function (x, nbasis, degree = 3, period = 1, names = NULL) {
+  y <- .Call(periodic_bspline_basis,x,nbasis,degree,period)
+  if (!is.null(names)) {
+    if (length(names)==1) {
+      nm <- sprintf(names,seq_len(nbasis))
+      if (length(unique(nm))!=nbasis)
+        nm <- paste(names,seq_len(nbasis),sep=".")
+      colnames(y) <- nm 
+    } else if (length(names)==nbasis) {
+      colnames(y) <- names
+    } else {
+      stop(sQuote("length(names)")," must be either 1 or ",nbasis)
+    }
+  }
+  y
+}

Modified: pkg/man/bsplines.Rd
===================================================================
--- pkg/man/bsplines.Rd	2011-04-27 14:59:10 UTC (rev 448)
+++ pkg/man/bsplines.Rd	2011-05-03 14:52:19 UTC (rev 449)
@@ -8,14 +8,22 @@
   \code{periodic.bspline.basis} gives a basis of periodic spline functions.
 }
 \usage{
-bspline.basis(x, nbasis, degree = 3)
-periodic.bspline.basis(x, nbasis, degree = 3, period = 1)
+bspline.basis(x, nbasis, degree = 3, names = NULL)
+periodic.bspline.basis(x, nbasis, degree = 3, period = 1, names = NULL)
 }
 \arguments{
   \item{x}{Vector at which the spline functions are to be evaluated.}
   \item{nbasis}{The number of basis functions to return.}
   \item{degree}{Degree of requested B-splines.}
   \item{period}{The period of the requested periodic B-splines.}
+  \item{names}{
+    optional; the names to be given to the basis functions.
+    These will be the column-names of the matrix returned.
+    If the names are specified as a format string (e.g., "basis%d"), \code{\link{sprintf}} will be used to generate the names from the column number.
+    If a single non-format string is specified, the names will be generated by \code{\link{paste}}-ing \code{name} to the column number.
+    One can also specify each column name explicitly by giving a length-\code{nbasis} string vector.
+    By default, no column-names are given.
+  }
 }
 \value{
   \item{bspline.basis}{
@@ -34,12 +42,12 @@
 \author{Aaron A. King \email{kingaa at umich dot edu}}
 \examples{
 x <- seq(0,2,by=0.01)
-y <- bspline.basis(x,degree=3,nbasis=9)
+y <- bspline.basis(x,degree=3,nbasis=9,names="basis")
 matplot(x,y,type='l',ylim=c(0,1.1))
 lines(x,apply(y,1,sum),lwd=2)
 
 x <- seq(-1,2,by=0.01)
-y <- periodic.bspline.basis(x,nbasis=5)
+y <- periodic.bspline.basis(x,nbasis=5,names="spline\%d")
 matplot(x,y,type='l')
 }
 \keyword{smooth}



More information about the pomp-commits mailing list