Skip to content

Commit

Permalink
try to pass targets test
Browse files Browse the repository at this point in the history
  • Loading branch information
cjvanlissa committed Sep 13, 2024
1 parent ed465fa commit 7640488
Showing 1 changed file with 29 additions and 10 deletions.
39 changes: 29 additions & 10 deletions tests/testthat/test-targets.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
library(targets)
test_that("targets works with apa6", {
the_test <- "targets"
old_wd <- getwd()
Expand All @@ -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)
})
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 7640488

Please sign in to comment.