Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quarto targets - indicate code chunk that causes error #99

Closed
3 tasks done
arnold-c opened this issue Jul 1, 2022 · 1 comment
Closed
3 tasks done

Quarto targets - indicate code chunk that causes error #99

arnold-c opened this issue Jul 1, 2022 · 1 comment
Assignees

Comments

@arnold-c
Copy link

arnold-c commented Jul 1, 2022

Prework

  • I understand and agree to the code of conduct and contributing guidelines.
  • If there is already a relevant issue, whether open or closed, comment on the existing thread instead of posting a new issue.
  • New features take time and effort to create, and they take even more effort to maintain. So if the purpose of the feature is to resolve a struggle you are encountering personally, please consider first posting a "trouble" or "other" issue so we can discuss your use case and search for existing solutions first.

Proposal

Thanks for adding Quarto targets - I've been eagerly following the feature progress on this one! Ideally, tar_quarto() would produce a similar error message to tar_render() i.e. specify the lines/code chunk that produce an error (without needing to inspect tar_meta() for quick debugging). Currently it just specifies that there is an error in the pipeline. MWE below altering the vignette example with a spelling error in the code chunk.

targets::tar_dir({  # tar_dir() runs code from a temporary directory.
    # Unparameterized Quarto document:
    lines <- c(
        "---",
        "title: report.qmd source file",
        "output_format: html",
        "---",
        "Assume these lines are in report.qmd.",
        "```{r}",
        # Note the incorrect spelling to cause an error
        "targets::tar_red(data)",
        "```"
    )
    writeLines(lines, "report.qmd")
    # Include the report in a pipeline as follows.
    targets::tar_script({
        library(tarchetypes)
        list(
            tar_target(data, data.frame(x = seq_len(26), y = letters)),
            tar_quarto(report, path = "report.qmd")
        )
    }, ask = FALSE)

    # Run pipeline
    targets::tar_make()
})
#> • start target report
#> ✖ error target report
#> • end pipeline: 2.266 seconds
#> Error : ! System command 'quarto' failed
#> ✖ Problem with the pipeline.
#> ℹ Show errors: tar_meta(fields = error, complete_only = TRUE)
#> ℹ Learn more: https://books.ropensci.org/targets/debugging.html
#> Error:
#> ! problem with the pipeline.

Created on 2022-07-01 by the reprex package (v2.0.1)

@wlandau
Copy link
Member

wlandau commented Jul 1, 2022

quiet = FALSE in tarchetypes::tar_quarto() prints the Quarto build log to the R console. But otherwise, I'm afraid this is outside my control because the error message generated by the quarto R package is "System command 'quarto' failed".

lines <- c(
  "---",
  "title: 'error'",
  "format: html",
  "editor: source",
  "---",
  "",
  "```{r}",
  "stop('true message')",
  "```"
)
writeLines(lines, "report.qmd")
tryCatch(
  quarto::quarto_render("report.qmd", quiet = TRUE),
  error = function(condition) {
    print(sprintf("Quarto error message: %s", conditionMessage(condition)))
  }
)
#> [1] "Quarto error message: ! System command 'quarto' failed"

Created on 2022-07-01 by the reprex package (v2.0.1)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants