[R] problem with switch function across R versions 2.10 and 2.13
Duncan Murdoch
murdoch.duncan at gmail.com
Tue Sep 27 22:19:23 CEST 2011
On 11-09-27 4:03 PM, jose romero wrote:
> Hello,
>
> The following piece of code works fine in R.2.10 (ubuntu):
>
> switch(distr,
> normal = {if (is.infinite(param["desv"]))
> n<- c(n,"La desv. estándar no puede ser Inf.")
> if (param["desv"]<0)
> n<- c(n,"La desv. estándar no puede ser<0.")
> },
> expo = {if (param["tasa"]<=0)
> n<- c(n,"La tasa debe ser>0.") },
> gamma = {if (param["s"]<=0)
> n<- c(n,"El parametro s debe ser>0.")
> if (param["a"]<=0)
> n<- c(n,"El parámetro a debe ser>0.") },
> unifc = {if (param["min"]>param["max"])
> n<- c(n,"Min. no puede ser mayor que Max.")},
> binom = {if (param["p"]<0|param["p"]>1)
> n<- c(n,"p debe estar entre 0 y 1")
> if (param["n"]<0|!all.equal(param["n"],
> trunc(param["n"])))
> n<- c(n,"Valor de n no entero o negativo.")
> if (param["n"]<max(x))
> n<- c(n,paste("El valor máximo de",nombre,
> "no puede exceder el valor máximo de n."))
> },
> geom = {if (param["p"]<0|param["p"]>1)
> n<- c(n,"p debe estar entre 0 y 1") },
> pois = {if (param["tasa"]<0)
> n<- c(n,"tasa no puede ser negativa")},
> unifd = {if (param["min"]>param["max"])
> n<- c(n,"minimo no puede ser mayor que maximo") }, ,
You have an extra comma beyond the end of this line.
Duncan Murdoch
> stop(paste("Distribución",distr,"no reconocida.")) )
>
> However, using R2.13 (under Windows), I get the following error:
> Error en .local(x, distr, ...) :
> duplicado de interuptores por defecto: '' y 'stop(paste...'
>
> The 2.13 help on the function says the following:
>
> In the case of no match, if there is a unnamed element of ... its value is returned. (If there is more than one such argument
> an error is returned. Before R 2.13.0 the first one would have
> been used.)
>
> So it appears to be an issue of the pre or post 2.13 version being used. However, i don't see how the above code has more than one unamed element and thus how this error is produced. Can anyone enlighten me on this error?
>
> Thanks in advance,
>
> josé loreto romero palma
> [[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.
More information about the R-help
mailing list