Skip to content

Commit 33555bd

Browse files
author
ripley
committed
add option R_LESS_COERCION_FROM_NULL, avoid as.logical(NULL)
git-svn-id: https://svn.r-project.org/R/trunk@87410 00db46b3-68df-0310-9c12-caf00c1e9a41
1 parent 159da97 commit 33555bd

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/library/base/R/funprog.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,9 @@ Filter <-
105105
function(f, x)
106106
{
107107
f <- match.fun(f)
108-
ind <- as.logical(unlist(lapply(x, f)))
108+
z <- unlist(lapply(x, f)) # could be NULL
109+
if(is.null(z)) return(x[integer()])
110+
ind <- as.logical(z)
109111
x[which(ind)]
110112
}
111113

@@ -128,7 +130,7 @@ Position <-
128130
function(f, x, right = FALSE, nomatch = NA_integer_)
129131
{
130132
f <- match.fun(f)
131-
133+
132134
ind <- if(right) rev(seq_along(x)) else seq_along(x)
133135

134136
for(i in ind)

src/main/coerce.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1379,6 +1379,8 @@ static SEXP asFunction(SEXP x)
13791379
return f;
13801380
}
13811381

1382+
//#define R_LESS_COERCION_FROM_NULL
1383+
// cannot yet build methods package with R_NO_LOGICAL_COERCION_FROM_NULL
13821384
static SEXP ascommon(SEXP call, SEXP u, SEXPTYPE type)
13831385
{
13841386
/* -> as.vector(..) or as.XXX(.) : coerce 'u' to 'type' : */
@@ -1397,6 +1399,11 @@ static SEXP ascommon(SEXP call, SEXP u, SEXPTYPE type)
13971399
if(TYPEOF(u) == NILSXP && type == INTSXP)
13981400
errorcall(call, _(COERCE_ERROR_STRING),
13991401
R_typeToChar(u), type2char(type));
1402+
#endif
1403+
#ifdef R_NO_LOGICAL_COERCION_FROM_NULL
1404+
if(TYPEOF(u) == NILSXP && type == LGLSXP)
1405+
errorcall(call, _(COERCE_ERROR_STRING),
1406+
R_typeToChar(u), type2char(type));
14001407
#endif
14011408
if (type != ANYSXP && TYPEOF(u) != type) v = coerceVector(u, type);
14021409
else v = u;

0 commit comments

Comments
 (0)