[R] Set default value

From: Michela Cameletti <michela.cameletti_at_unibg.it>
Date: Tue, 01 Jul 2008 14:02:28 +0200

 <R-help_at_lists.r-project.org>Hi, i'm tryng to build a function that take some input from user and if the user doesn't provide that inputs the function should set a deafult value. I have taken as example a function that i found in the package dlm but with the same code i receive an error (the component is missing...). According to the code below R seems to set 1 to "phi" instead of "p" ! The only way to solve this problem that i found is to change "p" to "P", but this is clearly the wrong solution ! There is some other way to set default value with that function structure ? Thanks,

Stem.Skeleton <- function(...) {

    if (nargs() == 1)

        x <- as.list(...)


        x <- list(...)

    ## required components

    comp <- c("phi", "p", "K")

if(is.null(list(x$p))) x$p = 1

compInd <- match(comp, names(x))

   if (any(is.na(compInd)))

        stop(paste("Component(s)", paste(comp[is.na(compInd)], collapse=", " ),

                   "is (are) missing"))


        [[alternative HTML version deleted]]

R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Tue 01 Jul 2008 - 12:05:56 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 01 Jul 2008 - 13:31:50 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive