Comments (7)
We could also use tidyselect
to choose which targets to apply the hooks.
from tarchetypes.
Also, let's consider supporting arbitrary expressions instead of just single-argument functions. A hook could look something like tar_hook_outer(target_object, hook = run_in_docker(code = .x, hostname = "localhost"))
, and the wrapped command could go in .x
.
from tarchetypes.
EDIT
Please see #44 (comment). I decided to veer away from in-place modifications.
original post
A few implementation issues that will probably come up repeatedly in subsequent discussions:
Composition of target lists
Should we return a flattened list of target objects, e.g. unlist(list(targets), recursive = TRUE)
, or should we keep the target list nested in the way the user defines it originally, e.g. tar_map(unlist = FALSE)
? I would think the latter. This outcome seems more likely to prevent surprises. Hooks should be minimally invasive when possible.
Modification in place
Should the hooks modify the target objects in place, or should they return deep copies of those objects? If we were to make deep copies, we would probably need to flatten the target list. (Recursing over an arbitrarily nested list and making arbitrary changes requires passing by reference unless we come up with some messy index scheme to keep track of where we are in the list at all times.) Above, we already decided against flattening the target list, so we should go with in-place modifications.
Return value
Given the decision to go with modification in place, we have a choice when it comes to the return value. We could either return the modified target list, or we could invisibly return NULL
. I strongly prefer the latter because it emphasizes that target objects are modified in place. The behavior is limiting, and it prevents the use of the magrittr
pipe, but it is a strong guardrail that I believe will prevent egregious and counterintuitive user errors.
Drawback: potential to accidentally drop targets
Users might not read the docs and incorrectly assume tar_hook_before()
returns target objects. In that case, those targets may not make it into the pipeline. This kind of mistake is not so costly because no extra runtime is spent on misspecified targets, so I think this is the right tradeoff.
Drawback: metaprogramming limitations
Users might want to apply multiple hooks to a common template target object. However, this is already possible with tar_map()
. The template can be created with tar_target()
and possibly tar_hook_first()
etc., and then tar_map()
could be invoked afterwards.
Best alternative
The best alternative I see to all this is to return a flattened list of deep-copied target objects. I still prefer not to do this because
- It would be more invasive, and
- Later on, if the demand is high enough, we can always build wrappers on top of
tar_hook_first()
etc. that make deep copies beforehand. We could either name those functionstar_hook_first_copy()
etc. or think of another term besides "hook". But let's try to pursue slick workarounds before we jump to an implementation.
from tarchetypes.
TL;DR: I am trying to make hooks safe, even if that makes them a bit limited (at first).
from tarchetypes.
On second thought, I think it's fine if hooks flatten the target list. I don't think people need the actual structure in a target list all that often.
from tarchetypes.
So #44 (comment) is a justification for flattening the target list, not modification in place.
from tarchetypes.
Implemented with the deep copy route.
from tarchetypes.
Related Issues (20)
- Local persistence of cloud-backed file targets HOT 5
- `tar_quarto()` always ends normally for quarto project even if there is error HOT 3
- `tar_quarto()` ignores `output_dir` in _quarto.yml when passed an individual file
- combine tar_cue_age with a conditional statement HOT 4
- Rep-specific seeds in tar_rep(), tar_map_rep(), etc. HOT 5
- optional garbage collection between reps of the `tar_rep*()` functions HOT 1
- tar_change repository not considered for change part
- Branches not in metadata: branches out of range
- GitHub interactions are temporarily limited because the maintainer is out of office.
- tar_cross() HOT 2
- Bug: `tar_quarto_rep()` throws an error if used together with `future::plan()` from _targets.R template HOT 1
- Support Quarto profiles? HOT 10
- Expose `tar_render()`, `tar_quarto()` and similar functions to the `deps` argument of `tar_target_raw()` HOT 8
- Errors and warnings with Quarto
- tar_quarto_rep doesn't work on reports in subdirectories HOT 2
- `retrieval = "none"` in quarto target factories HOT 2
- [general] Use `tar_rep()` and `tar_rep2()` inside of `tar_map()` HOT 2
- Allow trailing comma in `tar_map()` HOT 1
- Let `tar_map()` substitute more fields, e.g., `priority` HOT 2
- Safely allow tar_quarto() etc. to run the report from a custom working directory HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tarchetypes.