unitar icon indicating copy to clipboard operation
unitar copied to clipboard

A target factory for tracking, but not duplicating, external targets

Open nsheff opened this issue 4 years ago • 1 comments

In #3, I we talked about 3 use cases for unitar, and created a target factory to track external targets into a secondary project.

But a common use case (for me at least) is to want to track the upstream target as an input without duplicating it. But as @wlandau said,

I think it might be difficult to make a sufficiently flexible target factory for (3).

I've been thinking about it a bit more. I think we could create a target factory that would take as input:

  1. An upstream target name
  2. A function call on that name.

I think it may be possible to use something like:

track_external_target = function(tname, ext_tname, func) {
  fullpath = unitar_path(ext_tname)
  name_file = paste0(sample_name, "_file")
  command_data = substitute(func(fullpath), env=list(fullpath=as.symbol(name_file), func=as.symbol(func)))

  list(
    tar_target_raw(name_file, fullpath, format = "file"),
    tar_target_raw(tname, command_data)
  )  
}

I just wanted to capture this as a separate issue

nsheff avatar May 06 '21 21:05 nsheff

Yeah, this actually seems similar to stantargets and jagstargets, which require the user to supply code just to generate Stan/JAGS data. Seems to have worked out well so far because the need for custom code is reduced in so many other places for those packages.

wlandau avatar May 07 '21 12:05 wlandau