Rapporter / pander

An R Pandoc Writer: Convert arbitrary R objects into markdown
http://rapporter.github.io/pander/
Open Software License 3.0
294 stars 65 forks source link

Unclear how pander::eval captures stdout. #372

Open andystopia opened 2 months ago

andystopia commented 2 months ago

When executing in the R REPL, I find a surprising (to me) result.

> pander::evals("print(1:4)")$stdout
NULL

I would expect this print statement to print to stdout and the results would be visible in the stdout field, but this is not the case.

  1. Is this the intended behavior?
  2. Is there a way to get the printed object?

For context, I'm trying to build a literate programming environment within the Typst typesetter.

Thanks to the maintainers for all your hard work, this seems like such a hard problem throughout all my research on it

daroczig commented 1 month ago

evals tries to do so many things that I'm embarrassed now looking at it after so many years since implementing it :blush: I would need some time to go through the details to check on the above, but after a quick check, I think you might be happier with pander::eval.msgs, no?

> eval.msgs("print(1:3)")
$src
[1] "print(1:3)"

$result
NULL

$output
NULL

$type
[1] "integer"

$msg
$msg$messages
NULL

$msg$warnings
NULL

$msg$errors
NULL

$stdout
[1] "[1] 1 2 3"
andystopia commented 1 month ago

Yess, I just tried it! That's so helpful!! Thank you so much :D