Learn R Programming

apollo (version 0.3.9)

apollo_expandLoop: Expands loops in a function or expression

Description

Expands loops replacing the index by its value. It also evaluates paste and paste0, and removes get.

Usage

apollo_expandLoop(f, apollo_inputs, validate = TRUE)

Value

A function or expression of the same type as input f, with eligible loops expanded.

Arguments

f

function (usually apollo_probabilities) inside which the name of the components are inserted.

apollo_inputs

List grouping most common inputs. Created by function apollo_validateInputs.

validate

Logical. If TRUE, the expanded function is evaluated and compared against the original function before being returned. TRUE by default.

Details

For example, the expression for(j in 1:3) V[[paste0('alt',j)]] = b1*get(paste0('x',j)) + b2*X[,j]

would be expanded into:

V[["alt1"]] = b1*x1 + b2*X[,1] V[["alt2"]] = b1*x2 + b2*X[,2] V[["alt3"]] = b1*x3 + b2*X[,3]