-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Labels
Description
- expr <- quote(lapply(data, function(x){if(x>5)x=x+1;x})) #get an expression
- vexpr <- va_compile(expr) #vectorize the expression
The value of expr:
> expr
lapply(data, function(x) {
if (x > 5)
x = x + 1
x
})The value of vexpr:
> vexpr
va_vec2list((function (x)
{
ifelse(x > 5, x = x + 1, NULL)
x
})({
if (!(exists(".va.data", inherits = FALSE) && (is.null(.vasrc.data) ||
identical(.vasrc.data, data)))) {
.va.data <- va_list2vec(data)
.vasrc.data <- data
}
.va.data
}))An error occurs as follows.
> eval(vexpr)
Error in ifelse(x > 5, x = x + 1, NULL) : replacement has length zero
In addition: Warning message:
In rep(no, length.out = length(ans)) :
'x' is NULL so the result will be NULLThe problem should be in ifelse statement.
> w = 1:10
> ifelse(w>5,w=w+1,NULL)
Error in ifelse(w > 5, w = w + 1, NULL) : unused argument (w = w + 1)
> w=ifelse(w>5,w+1,w)
> w
[1] 1 2 3 4 5 7 8 9 10 11Reactions are currently unavailable