-
A quick reprex shows that modifying a function called in the R Markdown doesn't invalidate the the report's output. Is there a way to somehow automatically declare these dependencies, or only with custom cues? targets::tar_dir({
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"))
}, ask = FALSE)
tar_make()
# Modify the function
writeLines(sub("x + 1", "x + 2", readLines("_targets.R"), fixed = TRUE),
"_targets.R")
tar_make()
})
#> • start target report
#> • built target report
#> • end pipeline
#> ✔ skip target report
#> ✔ skip pipeline Created on 2021-09-16 by the reprex package (v2.0.1) Session infosessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#> setting value
#> version R version 4.1.1 (2021-08-10)
#> os Ubuntu 20.04.3 LTS
#> system x86_64, linux-gnu
#> ui X11
#> language (EN)
#> collate en_US.UTF-8
#> ctype en_US.UTF-8
#> tz Etc/UTC
#> date 2021-09-16
#>
#> ─ Packages ───────────────────────────────────────────────────────────────────
#> package * version date lib source
#> callr 3.7.0 2021-04-20 [1] RSPM (R 4.0.4)
#> cli 3.0.1 2021-07-17 [1] RSPM (R 4.1.0)
#> codetools 0.2-18 2020-11-04 [3] CRAN (R 4.0.3)
#> crayon 1.4.1 2021-02-08 [1] RSPM (R 4.0.3)
#> data.table 1.14.0 2021-02-21 [1] RSPM (R 4.0.3)
#> digest 0.6.27 2020-10-24 [1] RSPM (R 4.0.3)
#> ellipsis 0.3.2 2021-04-29 [1] RSPM (R 4.0.4)
#> evaluate 0.14 2019-05-28 [1] RSPM (R 4.0.0)
#> fansi 0.5.0 2021-05-25 [1] RSPM (R 4.1.0)
#> fastmap 1.1.0 2021-01-25 [1] RSPM (R 4.0.3)
#> fs 1.5.0 2020-07-31 [1] RSPM (R 4.0.2)
#> glue 1.4.2 2020-08-27 [1] RSPM (R 4.0.2)
#> highr 0.9 2021-04-16 [1] CRAN (R 4.0.5)
#> htmltools 0.5.2 2021-08-25 [1] CRAN (R 4.1.1)
#> igraph 1.2.6 2020-10-06 [1] RSPM (R 4.1.0)
#> knitr 1.34 2021-09-09 [1] RSPM (R 4.1.0)
#> lifecycle 1.0.0 2021-02-15 [1] RSPM (R 4.0.3)
#> magrittr 2.0.1 2020-11-17 [1] RSPM (R 4.0.3)
#> pillar 1.6.2 2021-07-29 [1] RSPM (R 4.1.0)
#> pkgconfig 2.0.3 2019-09-22 [1] RSPM (R 4.0.0)
#> processx 3.5.2 2021-04-30 [1] RSPM (R 4.0.4)
#> ps 1.6.0 2021-02-28 [1] RSPM (R 4.0.3)
#> purrr 0.3.4 2020-04-17 [1] RSPM (R 4.0.0)
#> R6 2.5.1 2021-08-19 [1] RSPM (R 4.1.0)
#> reprex 2.0.1 2021-08-05 [1] CRAN (R 4.1.0)
#> rlang 0.4.11 2021-04-30 [1] RSPM (R 4.0.4)
#> rmarkdown 2.11 2021-09-14 [1] CRAN (R 4.1.1)
#> sessioninfo 1.1.1 2018-11-05 [1] RSPM (R 4.0.0)
#> stringi 1.7.4 2021-08-25 [1] CRAN (R 4.1.1)
#> stringr 1.4.0 2019-02-10 [1] RSPM (R 4.0.0)
#> targets * 0.7.0.9001 2021-09-16 [1] Github (ropensci/targets@d972f61)
#> tibble 3.1.4 2021-08-25 [1] CRAN (R 4.1.1)
#> tidyselect 1.1.1 2021-04-30 [1] RSPM (R 4.0.4)
#> utf8 1.2.2 2021-07-24 [1] RSPM (R 4.1.0)
#> vctrs 0.3.8 2021-04-29 [1] RSPM (R 4.0.4)
#> withr 2.4.2 2021-04-18 [1] CRAN (R 4.0.5)
#> xfun 0.26 2021-09-14 [1] CRAN (R 4.1.1)
#> yaml 2.2.1 2020-02-01 [1] RSPM (R 4.0.0)
#>
#> [1] /usr/local/lib/R/site-library
#> [2] /usr/lib/R/site-library
#> [3] /usr/lib/R/library |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
You can use the 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),
"_targets.R")
tar_make()
#> • start target report
#> • built target report
#> • end pipeline Created on 2021-09-20 by the reprex package (v2.0.1) |
Beta Was this translation helpful? Give feedback.
-
Thanks! It would be cool if targets could discover all global functions automatically in an R Markdown file, so the user won't forget to declare dependencies manually. Although I can see how this might be a niche use case. |
Beta Was this translation helpful? Give feedback.
You can use the
...
arguments intar_render()
. That will change the command of the target to include some mentions of functions. Sketch: