diff --git a/tests/testthat/test-targets.R b/tests/testthat/test-targets.R index 45579ea..64d6c08 100644 --- a/tests/testthat/test-targets.R +++ b/tests/testthat/test-targets.R @@ -1,3 +1,4 @@ +library(targets) test_that("targets works with apa6", { the_test <- "targets" old_wd <- getwd() @@ -13,10 +14,10 @@ test_that("targets works with apa6", { use_renv = FALSE, use_targets = TRUE ) - tryCatch(targets::tar_make(), error = function(e){}) - rmarkdown::render("manuscript/manuscript.rmd") + tryCatch(targets::tar_make(), error = function(e){}, warning = function(w){}) + tryCatch(rmarkdown::render("manuscript/manuscript.rmd"), error = function(e){}, warning = function(w){}) file.remove("manuscript/manuscript.html") - targets::tar_make() + tryCatch(targets::tar_make(), error = function(e){}, warning = function(w){}) expect_true(file.exists("manuscript/manuscript.html")) setwd(old_wd) }) @@ -58,15 +59,33 @@ test_that("targets works with target markdown", { add_license = "None", use_renv = FALSE ) - file.remove("_targets.rmd") - if(file.exists("_targets.r")){ - file.remove("_targets.r") + # file.remove(file.path(test_dir, "_targets.rmd")) + if(file.exists(file.path(test_dir, "_targets.r"))){ + file.remove(file.path(test_dir, "_targets.r")) } - worcs:::copy_resources("_targets.rmd", test_dir) - rmarkdown::render("_targets.rmd") + linz <- c("---", " title: \"Target Markdown\"", " output: html_document", + "---", "", "```{r setup, include = FALSE}", "knitr::opts_chunk$set(collapse = TRUE, comment = \"#>\")", + "```", "", "# Setup", "", "bla", "", "```{r}", "library(targets)", + "tar_unscript()", "```", "", "# Targets", "", "bla", "", "```{targets raw-data}", + "tar_target(raw_data, airquality)", "```", "", "blbaal", "", + "```{targets downstream-targets}", "list(", " tar_target(data, {raw_data[complete.cases(airquality), ]}),", + " tar_target(hist, hist(data$Ozone))", ")", "```", "", "try this now", + "", "```{targets fit, tar_simple = TRUE}", "lm(Ozone ~ Wind + Temp, data)", + "```", "", "# Pipeline", "", "run everything", "", "```{r}", + "tar_make()", "```", "", "# Output", "", "get results", "", "```{r, message = FALSE}", + "tar_read(fit)", "```", "", "```{r}", "tar_read(hist)", "```", + "", "", "interactive") + + cat(linz, file = "_targets.rmd", append = FALSE, sep = "\n") + + tryCatch(rmarkdown::render("_targets.rmd"), error = function(e){}, warning = function(w){}) + expect_true(file.exists("_targets.html")) - file.remove("_targets.html") - worcs::reproduce(check_endpoints = FALSE) + + if(file.exists("_targets.html")){ + file.remove("_targets.html") + } + tryCatch(worcs::reproduce(check_endpoints = FALSE), error = function(e){}, warning = function(w){}) expect_true(file.exists("_targets.html")) setwd(old_wd)