Skip to content

Commit 2efd0c0

Browse files
author
ripley
committed
add asRbool as a safer version of (Rboolean)asLogical
git-svn-id: https://svn.r-project.org/R/trunk@87774 00db46b3-68df-0310-9c12-caf00c1e9a41
1 parent c64e4b5 commit 2efd0c0

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/include/Defn.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ Rcomplex Rf_ComplexFromReal(double, int*);
103103
Memory.h, PrtUtil.h, Utils.h */
104104
#undef CALLED_FROM_DEFN_H
105105

106+
Rboolean Rf_asRbool(SEXP x,SEXP call);
107+
108+
106109
/* UUID identifying the internals version -- packages using compiled
107110
code should be re-installed when this changes */
108111
#define R_INTERNALS_UUID "2fdf6c18-697a-4ba7-b8ef-11c0d92f1327"
@@ -1727,6 +1730,7 @@ int R_NaN_is_R_NA(double);
17271730
void R_RestoreHashCount(SEXP rho);
17281731

17291732
# define allocCharsxp Rf_allocCharsxp
1733+
# define asRbool Rf_asRbool
17301734
# define asVecSize Rf_asVecSize
17311735
# define asXLength Rf_asXLength
17321736
# define begincontext Rf_begincontext

src/main/coerce.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1824,6 +1824,14 @@ int asLogical(SEXP x)
18241824
return asLogical2(x, /* checking = */ 0, R_NilValue);
18251825
}
18261826

1827+
Rboolean asRbool(SEXP x, SEXP call)
1828+
{
1829+
int ans = asLogical2(x, 1, call);
1830+
if (ans == NA_LOGICAL)
1831+
errorcall(call, _("NA in coerciaon to Rboolean"));
1832+
return ans;
1833+
}
1834+
18271835

18281836
int asInteger(SEXP x)
18291837
{

0 commit comments

Comments
 (0)