yihui / knitr

A general-purpose tool for dynamic report generation in R
https://yihui.org/knitr/
2.38k stars 876 forks source link

Knit engine does work in RMarkdown but not in Quarto #2259

Closed rkrug closed 1 year ago

rkrug commented 1 year ago

Hi I am have a knit engine in my package which works in RMarkdown but not in Quarto

The definition of the k nit w=engine can be found here: https://github.com/rkrug/plantuml/blob/master/R/plantuml_knit_engine.R

As an example, please see https://github.com/rkrug/plantuml/blob/master/vignettes/use_with_knitr.Rmd which works, but if I change the document to a quarto document, the plantuml graphs are generated (presumably - compile time is similar) but the the created graphs are not found, i.e. shown as these placeholder "?" images.

I assume, it is a small thing, but are there things to consider when using custom knit engines in quarto?

Thanks,

Rainer


By filing an issue to this repo, I promise that

I understand that my issue may be closed if I don't fulfill my promises.

cderv commented 1 year ago

I assume, it is a small thing, but are there things to consider when using custom knit engines in quarto?

Usually nothing specific but though a different in default behavior.

With Quarto, R will run only to execute the code. R process will be opened, and then close. Among other things, this means that nothing in the temp directory will stay.

In your engine, it seems you are using the temp directory to store the file created. And we can see that in the link to the file inserted in the output.

https://github.com/rkrug/plantuml/blob/5d6f8a1955551fff342d0a856ab9416c9beb6381/R/plantuml_knit_engine.R#L75

For resources, it is better to store them along the document, best is in the resoure dir with other files. I believe you were planning to that with the plantuml.path option but I don't see it used

https://github.com/rkrug/plantuml/blob/5d6f8a1955551fff342d0a856ab9416c9beb6381/R/plantuml_knit_engine.R#L13-L14 https://github.com/rkrug/plantuml/blob/5d6f8a1955551fff342d0a856ab9416c9beb6381/R/plantuml_knit_engine.R#L38-L42

Should tmpdir() be replaced by path ?

Hope this helps

rkrug commented 1 year ago

Now it makes perfect sense.

The idea of the 'plantuml.path' was not for this purpose, but it can be used for that. Thanks.

cderv commented 1 year ago

The idea of the 'plantuml.path' was not for this purpose, but it can be used for that. Thanks.

Ok so I missed what this option is doing.

But you probably don't need it here. You just need to write your file in the resource dir. It would make sense to use fig.path option to put it with other figure creating from a R chunk.

rkrug commented 1 year ago

By the way - do I have access to the chunk label (if it has one) in the knit engine?

cderv commented 1 year ago

yes look at opts_current$get() to get options from a chunk. opts_current$get("label") will get you the label

rkrug commented 1 year ago

OK - thanks. Will this be a unique label if the chunk has no label explicitly assigned?

rkrug commented 1 year ago

Perfect - works like a charm, and uses "unnamed-chunk-x" as the label as hoped.

github-actions[bot] commented 10 months ago

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary.