Skip to content

print implementations should not mix output to stdout and messages from cli functions #277

Closed
@brookslogan

Description

@brookslogan

E.g., mixing cat (printing to output stream) and {cli} functions ([issuing messages that knitr intercepts or] printing to message stream) in print.epi_recipe and print.frosting leads to some trouble with knitting documents.

E.g., trying to rebuild forecast-framework.qmd in delphi-tooling book has this in a chunk with #| collapse: true earlier in the document for printing an epi_recipe:

#> ── Operations
#> 1.
#> Lagging: case_rate by 0, 7, 14 | Trained
#> 2.
#> Lagging: death_rate by 0, 7, 14 | Trained
#> 3.
#> Leading: death_rate by 7 | Trained
#> 4.
#> • Removing rows with NA values in: lag_0_case_rate, ... | Trained
#> 5.
#> • Removing rows with NA values in: ahead_7_death_rate | Trained
#> 6.
#> • # of recent observations per key limited to:: Inf | Trained

or, when printing a frosting with some other set of options:

2023-12-15-023636_759x588_scrot

It also messes with capture.output, which only captures one stream at a time (ordering is lost).

Potential fixes:

  • See if cat can print to message stream via file argument.
  • Replace cat with something like cli::cli_text with appropriate escaping/interpolation of programmatically-constructed/user-input/etc. strings, if it outputs in an acceptable format.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions