[Rd] switch() called with just the EXPR argument causes R to hang (PR#14124)
sgiannerini at gmail.com
sgiannerini at gmail.com
Thu Dec 10 09:30:10 CET 2009
Dear all,
switch() called with just the EXPR argument causes R to hang so that the
only way to stop it is to kill R.
Reproducible example:
> switch(EXPR="a")
the internal C subroutine behind switch is do_switch located in
R/src/main/builtin.c
For convenience I reproduce it below.
*****************************************************************************
SEXP attribute_hidden do_switch(SEXP call, SEXP op, SEXP args, SEXP rho)
{
int argval;
SEXP x, y, w;
x = eval(CAR(args), rho);
if (!isVector(x) || length(x) != 1)
error(_("switch: EXPR must return a length 1 vector"));
PROTECT(w = switchList(CDR(args), rho));
if (isString(x)) {
for (y = w; y != R_NilValue; y = CDR(y))
if (TAG(y) != R_NilValue && pmatch(STRING_ELT(x, 0), TAG(y), 1)) {
while (CAR(y) == R_MissingArg && y != R_NilValue)
y = CDR(y);
UNPROTECT(1);
return (eval(CAR(y), rho));
}
for (y = w; y != R_NilValue; y = CDR(y))
if (TAG(y) == R_NilValue) {
UNPROTECT(1);
return (eval(CAR(y), rho));
}
UNPROTECT(1);
return R_NilValue;
}
argval = asInteger(x);
if (argval <= 0 || argval > (length(w))) {
UNPROTECT(1);
return R_NilValue;
}
x = eval(CAR(nthcdr(w, argval - 1)), rho);
UNPROTECT(1);
return x;
}
**************************************************************************
I do not know C but it seems to me that do_switch expects two arguments.
regards
Simone
tested both on Windows VISTA 32 bit
platform i386-pc-mingw32
arch i386
os mingw32
system i386, mingw32
status
major 2
minor 10.0
year 2009
month 10
day 26
svn rev 50208
language R
version.string R version 2.10.0 (2009-10-26)
and on Linux OpenSuSE 11.0 64bit
> R.version
_
platform x86_64-unknown-linux-gnu
arch x86_64
os linux-gnu
system x86_64, linux-gnu
status Patched
major 2
minor 10.0
year 2009
month 11
day 19
svn rev 50499
language R
version.string R version 2.10.0 Patched (2009-11-19 r50499)
--
______________________________________________________
Simone Giannerini
Dipartimento di Scienze Statistiche "Paolo Fortunati"
Universita' di Bologna
Via delle belle arti 41 - 40126 Bologna, ITALY
Tel: +39 051 2098262 Fax: +39 051 232153
http://www2.stat.unibo.it/giannerini/
______________________________________________________
[[alternative HTML version deleted]]
More information about the R-devel
mailing list