Skip to content

Commit

Permalink
Merge pull request #22 from D-Se/safe
Browse files Browse the repository at this point in the history
Safe
  • Loading branch information
D-Se committed Nov 29, 2023
2 parents cbdb565 + 5574f50 commit 5a853c8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 3 additions & 0 deletions inst/tinytest/test_err.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ err <- "err"

(TRUE ?~! er) := NULL
error(FALSE ?~! err, err)

t <- "a message"
error(FALSE ?~! t, "a message")
5 changes: 4 additions & 1 deletion src/ifelse.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ S rhs(S fml) {
SEXP expr = CADR(fml);
if(TYPEOF(expr) == LANGSXP && CAR(expr) == Rf_install("!")) { // x ?~! y
SEXP msg = CADR(expr);
err(str2char(TYPEOF(msg) == STRSXP ? msg : Rf_eval(msg, ENV(fml))));
if (TYPEOF(msg) != STRSXP) {
msg = Rf_eval(msg, ENV(fml));
}
Rf_errorcall(R_NilValue, "%s", str2char(msg)); // ensure string literal
} else {
return Rf_eval(expr, ENV(fml)); // ~x
}
Expand Down

0 comments on commit 5a853c8

Please sign in to comment.