Closed multimeric closed 1 year ago
Thanks for this idea!
I knew my original approach was brittle because we have two copies of the targets plan, but didn't have a good solution at the time.
Unfortunately I don't have time to work on this ATM (probably not for a few more weeks), but this sounds good to me. If you want to refactor (or start on refactoring) the code that would be great.
Great! That's okay, I should have time to write a PR for this in the next week, I just wanted to run it by you first.
Awesome, thanks!
The currently used approach to displaying and then running targets workflows in the lesson is to:
_targets.R
file in the Rmd file, but to set it toeval=FALSE
write_example_plan
echo=FALSE
, which useswrite_example_plan()
to write and execute a copy of the workflow.An example can be seen here: https://github.com/carpentries-incubator/targets-workshop/blob/4588d719f590d134aea783152cd1bd4c7695f012/episodes/branch.Rmd#L69-L101.
It occurred to me that we could maybe improve this by using some knitr features, and avoid the issue of needing to synchronise the two copies of the script.
First we move all the example workflows (
_targets.R
) files into a directory, let's sayepisodes/files/plan_3.R
. Then in the Rmd we use thefile=
option to knitr, which loads the chunk from a file on disk and displays it. This does work with sandpaper, I've verified it myself:This simplifies both of the chunks quite a lot, should increase maintainability, and makes it easier to edit the sample workflows. Thoughts?