Skip to content

Can we avoid for loops? #6

@PhDyellow

Description

@PhDyellow

@jaseeverett, I notice in the programming section, we teach people to use for loops. For parallel processing, it is much better to be using lapply.

We could also use foreach.

Moving from a for loop to lapply or foreach is a major refactor, because the for loop expects variables outside the loop to be initialised, and expects to be modifying those variables during the loop. lapply and foreach create a new scope inside, so that generally you use them as functions that take inputs and return lists.

Moving from lapply to parLapply or future_lapply is only a minor refactor, with an extra line of code at the start of the script to specify the parallel model.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions