Skip to content

Why does do.call work in tar_target, but not in a target factory? #461

Closed Answered by wlandau
nsheff asked this question in Help
Discussion options

You must be logged in to vote

tar5 is disconnected from the graph because part of the R command is actually a list.

View(load_custom("tar5", "sum", list("tar1", "tar2"))$command$expr)

To avoid this problem, I would create an expression representation of args instead of inserting args directly via substitute(). Elements of env should be symbols or expressions. The following works for me:

load_custom = function(tname, func, args) {
  args_expr = as.call(c(as.symbol("list"), lapply(args, as.symbol)))
  command_data = substitute(
    do.call(func, args),
    env = list(args = args_expr, func = as.symbol(func))
  )
  tar_target_raw(tname, command_data)
}

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@nsheff
Comment options

Answer selected by nsheff
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
2 participants