Skip to content

A problem in branch #1

@wukefe

Description

@wukefe
  1. expr <- quote(lapply(data, function(x){if(x>5)x=x+1;x})) #get an expression
  2. 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 NULL

The 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 11

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions