Skip to content

Commit

Permalink
numeric vs double in error msgs (and trust coerceVector() works)
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.r-project.org/R/trunk@87678 00db46b3-68df-0310-9c12-caf00c1e9a41
  • Loading branch information
maechler committed Feb 3, 2025
1 parent d5d4863 commit 0a76818
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 14 deletions.
1 change: 0 additions & 1 deletion src/library/grDevices/src/chull.c
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,6 @@ SEXP chull(SEXP x)
for (int i = 0; i < n; i++) in[i] = i+1;
int *ih = (int*)R_alloc(4*n, sizeof(int));
x = PROTECT(coerceVector(x, REALSXP));
if(TYPEOF(x) != REALSXP) error("'x' is not numeric");
in_chull(&n, REAL(x), &n, in, ih+n, ih+2*n, ih, &nh, ih+3*n);
SEXP ans = allocVector(INTSXP, nh);
int *ians = INTEGER(ans);
Expand Down
2 changes: 1 addition & 1 deletion src/library/graphics/src/base.c
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ static SEXP baseCallback(GEevent task, pGEDevDesc dd, SEXP data)
/* Modify the saved settings so this effects display list too */
ddpSaved->scale *= rf;
} else
error("event 'GE_ScalePS' requires a single numeric value");
error("event 'GE_ScalePS' requires a single numeric (double) value");
break;
}
}
Expand Down
13 changes: 6 additions & 7 deletions src/library/stats/src/port.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* R : A Computer Language for Statistical Data Analysis
* Copyright (C) 2005-2024 The R Core Team.
* Copyright (C) 2005-2025 The R Core Team.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -382,16 +382,15 @@ SEXP port_nlminb(SEXP fn, SEXP gr, SEXP hs, SEXP rho,
if (isNull(rho)) {
error(_("use of NULL environment is defunct"));
rho = R_BaseEnv;
} else
if (!isEnvironment(rho))
} else if (!isEnvironment(rho))
error(_("'rho' must be an environment"));
if (!isReal(d) || n < 1)
error(_("'d' must be a nonempty numeric vector"));
error(_("'d' must be a nonempty numeric (double) vector"));
if (hs != R_NilValue && gr == R_NilValue)
error(_("When Hessian defined must also have gradient defined"));
if (R_NilValue == (xpt = findVarInFrame(rho, dot_par_symbol)) ||
!isReal(xpt) || LENGTH(xpt) != n)
error(_("environment 'rho' must contain a numeric vector '.par' of length %d"),
error(_("environment 'rho' must contain a numeric (double) vector '.par' of length %d"),
n);
/* We are going to alter .par, so must duplicate it */
defineVar(dot_par_symbol, duplicate(xpt), rho);
Expand All @@ -405,7 +404,7 @@ SEXP port_nlminb(SEXP fn, SEXP gr, SEXP hs, SEXP rho,
b[2*i] = rl[i];
b[2*i + 1] = ru[i];
}
} else error(_("'lower' and 'upper' must be numeric vectors"));
} else error(_("'lower' and 'upper' must be numeric (double) vectors"));
}
if (gr != R_NilValue) {
g = (double *)R_alloc(n, sizeof(double));
Expand Down Expand Up @@ -552,7 +551,7 @@ SEXP port_nlsb(SEXP m, SEXP d, SEXP gg, SEXP iv, SEXP v,
*rd = (double *)R_alloc(nd, sizeof(double));

if (!isReal(d) || n < 1)
error(_("'d' must be a nonempty numeric vector"));
error(_("'d' must be a nonempty numeric (double) vector"));
if(!isNewList(m)) error(_("m must be a list"));
/* Initialize parameter vector */
getPars = PROTECT(lang1(getFunc(m, "getPars", "m")));
Expand Down
6 changes: 1 addition & 5 deletions src/main/raw.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,6 @@ attribute_hidden SEXP do_numToInts(SEXP call, SEXP op, SEXP args, SEXP env)
{
checkArity(op, args);
SEXP x = PROTECT(coerceVector(CAR(args), REALSXP));
if (!isReal(x))
error(_("argument 'x' must be a numeric vector"));
SEXP ans = PROTECT(allocVector(INTSXP, 2*XLENGTH(x)));
R_xlen_t i, j = 0;
double *x_ = REAL(x);
Expand All @@ -169,13 +167,11 @@ attribute_hidden SEXP do_numToInts(SEXP call, SEXP op, SEXP args, SEXP env)
UNPROTECT(2);
return ans;
}
// split "real", i.e. = double = 64-bitd, to bits (<==> do_intToBits( do_numToInts(..) .. ))
// split "real", i.e. = double = 64-bit, to bits (<==> do_intToBits( do_numToInts(..) .. ))
attribute_hidden SEXP do_numToBits(SEXP call, SEXP op, SEXP args, SEXP env)
{
checkArity(op, args);
SEXP x = PROTECT(coerceVector(CAR(args), REALSXP));
if (!isReal(x))
error(_("argument 'x' must be a numeric vector"));
SEXP ans = PROTECT(allocVector(RAWSXP, 64*XLENGTH(x)));
R_xlen_t i, j = 0;
double *x_ = REAL(x);
Expand Down

0 comments on commit 0a76818

Please sign in to comment.