Rahul
Rahul

Reputation: 2769

`knitr_out, `file_out` and `vis_drake_graph` usage in R:drake

I'm trying to understand how to use knitr_out, file_out and vis_drake_graph properly in drake.

I have two questions.

Q1: Usage of knitr_out and file_out to create markdown reports

While a code like this works correctly for one of my smaller projects:

make_hyp_data_aggregated_report <- function() {
        render(
                input = knitr_in("rmd/hyptest-is-data-being-aggregated.Rmd"),
                output_file = file_out("~/projectname/reports/01-hyp-test.html"),
                quiet = TRUE
        )
}

plan <- drake_plan(
        ...
        ...
        hyp_data_aggregated_report = make_hyp_data_aggregated_report()
        ...
        ...
) 

enter image description here

Exactly similar code in my large project (with ~10+ reports) doesn't work exactly right. i.e., while the reports get built, the knitr_in objects don't get displayed as the blue squares in the graph using drake::vis_drake_graph() in my large project.

Both projects use the drake::loadd(....) within the markdown to get the objects from cache.

Is there some code in vis_drake_graph that removes these squares once the graph gets busy?

Q2: file_out objects in vis_drake_graph

Is there a way to display the file_out objects themselves as circles/squares in vis_drake_graph?

Q3: packages showing up in vis_drake_graph

Is there a way to avoid vis_drake_graph from printing the packages explicitly? (Basically anything with the ::)

enter image description here

Upvotes: 0

Views: 73

Answers (1)

landau
landau

Reputation: 5841

Q1

Every literal file path needs its own knitr_in() or file_out(). If you have one function with one knitr_in(), even if you use the function multiple times, that still only counts as one file path. I recommend writing these keywords at the plan level, e.g.

plan <- drake_plan(
  r1 = render(knitr_in("report1.Rmd"), output_file = file_out("report1.html")),
  r2 = render(knitr_in("report2.Rmd"), output_file = file_out("report2.html")),
  r3 = render(knitr_in("report3.Rmd"), output_file = file_out("report3.html"))
)

Q2

They should appear unless you set show_output_files = FALSE in vis_drake_graph().

Q3

No, but if it's any consolation, I do regret the decision to track namespaced functions and objects at all in drake. drake's approach is fundamentally suboptimal for tracking packages, and I plan to get rid of it if there ever comes time for a round of breaking changes. Otherwise, there is no way to get rid of it except vis_drake_graph(targets_only = TRUE), which also gets rid of all the imports in the graph.

Upvotes: 1

Related Questions