Skip to content

How to declare function dependencies in R Markdown documents? #70

Closed Answered by wlandau
svraka asked this question in Help
Discussion options

You must be logged in to vote

You can use the ... arguments in tar_render(). That will change the command of the target to include some mentions of functions. Sketch:

library(targets)

report <- c("---",
            "title: title",
            "---",
            "```{r}",
            "fun(1)",
            "```")
writeLines(report, "report.Rmd")

tar_script({
  library(tarchetypes)
  fun <- function(x) x + 1
  list(
    tar_render(
      report,
      "report.Rmd",
      params = list(fun = fun) # example: function as a parameter
    )
  )
}, ask = FALSE)

tar_make()
#> • start target report
#> • built target report
#> • end pipeline
writeLines(sub("x + 1", "x + 2", readLines("_targets.R"), fixed = TRUE),
           "_…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by svraka
Comment options

You must be logged in to vote
2 replies
@wlandau
Comment options

@svraka
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
2 participants