Skip to content

ignoreIndexRanges argument for FORLOOP - #42

Merged
kenkellner merged 7 commits into
masterfrom
FORLOOP_ignore_argument
Jun 10, 2026
Merged

kenkellner merged 7 commits into
masterfrom
FORLOOP_ignore_argument

Conversation

@kenkellner

@kenkellner kenkellner commented Jun 10, 2026 •

Copy link
Copy Markdown
Collaborator

Adds an ignoreIndexRanges argument to the FORLOOP macro. You can provide a list of index ranges to the argument and they will be ignored when constructing the loop. For example:

x[1:n] <- FORLOOP(sum(y[1:n, 1:3]), ignoreIndexRanges = list(quote(1:3)))

will return

for (i in 1:n){
  x[i] <- sum(y[i, 1:3])
}

Because the FORLOOP macro, for flexibility reasons, doesn't use the use3pieces or unpackArgs arguments to buildMacro, the implementation of this argument is a bit clunky. The line of code with the macro call goes into the macro function as one undifferentiated line of quoted code, so we need to extract and evaluate the content of the argument

ignore <- eval(code[[length(code)]]$ignoreIndexRanges, envir = .env)

and then remove it from the line of code so the rest of it can be processed

code[[length(code)]]$ignoreIndexRanges <- NULL

Fixes #41

@kenkellner kenkellner changed the title Ignore argument for FORLOOP ignoreIndexRanges argument for FORLOOP Jun 10, 2026
@kenkellner kenkellner changed the title ignoreIndexRanges argument for FORLOOP ignoreIndexRanges argument for FORLOOP Jun 10, 2026
@kenkellner
kenkellner merged commit 4d24465 into master Jun 10, 2026
1 check passed
@kenkellner
kenkellner deleted the FORLOOP_ignore_argument branch June 10, 2026 18:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Should be a way to tell FORLOOP to ignore certain index ranges

1 participant