databio / unitar

Targets that span projects in R
http://unitar.databio.org
Other
17 stars 0 forks source link

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

Open nsheff opened 3 years ago

nsheff commented 3 years ago

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

wlandau commented 3 years ago

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.