Skip to content

Use tar_map() to reduce duplicated code #374

@Robinlovelace

Description

@Robinlovelace

From the targets manual:

Sometimes, a pipeline contains more targets than a user can comfortably type by hand. For projects with hundreds of targets, branching can make the _targets.R file more concise and easier to read and maintain.

Just saw this tip from @andrewheiss (thanks for sharing):

Finally figured out how to dynamically make {targets} targets through metaprogramming (https://books.ropensci.org/targets/static.html#metaprogramming) and it's SO NICE to have nice clean target names that are automatically generated #rstats

Source: https://fosstodon.org/@andrew@fediscience.org/111689215513772257

Currently our code has a lot of bits like this:

npt/_targets.R

Lines 322 to 328 in f1ae9eb

tar_target(r_commute_fastest, {
rs_commute_fastest[[1]]$routes
}),
tar_target(r_commute_quietest, {
rs_commute_quietest[[1]]$routes
}),

An iterator like tar_map() could compress those 3 targets into a single function call, reducing complexity and easing readability and maintenance.

Metadata

Metadata

Assignees

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