Skip to content

Commit 42ab1b5

Browse files
author
ripley
committed
add asBool2
git-svn-id: https://svn.r-project.org/R/trunk@87841 00db46b3-68df-0310-9c12-caf00c1e9a41
1 parent d900655 commit 42ab1b5

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/include/Defn.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ Rcomplex Rf_ComplexFromReal(double, int*);
104104
#undef CALLED_FROM_DEFN_H
105105

106106
Rboolean Rf_asRbool(SEXP x,SEXP call);
107+
bool Rf_asBool2(SEXP x,SEXP call);
107108

108109

109110
/* UUID identifying the internals version -- packages using compiled
@@ -1730,6 +1731,7 @@ int R_NaN_is_R_NA(double);
17301731
void R_RestoreHashCount(SEXP rho);
17311732

17321733
# define allocCharsxp Rf_allocCharsxp
1734+
# define asBool2 Rf_asBool2
17331735
# define asRbool Rf_asRbool
17341736
# define asVecSize Rf_asVecSize
17351737
# define asXLength Rf_asXLength

src/main/coerce.c

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

1827-
// private version
1827+
// private versions
18281828
Rboolean asRbool(SEXP x, SEXP call)
18291829
{
18301830
int ans = asLogical2(x, 1, call);
@@ -1833,6 +1833,14 @@ Rboolean asRbool(SEXP x, SEXP call)
18331833
return (Rboolean) ans;
18341834
}
18351835

1836+
bool asBool2(SEXP x, SEXP call)
1837+
{
1838+
int ans = asLogical2(x, 1, call);
1839+
if (ans == NA_LOGICAL)
1840+
errorcall(call, _("NA in coercion to Rboolean"));
1841+
return (bool) ans;
1842+
}
1843+
18361844
// public version
18371845
Rboolean asRboolean(SEXP x)
18381846
{

0 commit comments

Comments
 (0)