Hemken / Statamarkdown

Functions to write Stata documentation with knitr
Other
59 stars 11 forks source link

Stata graphics hook #28

Open kylebutts opened 2 years ago

kylebutts commented 2 years ago

Is it possible to use a chunk option to plot specific lines of stata code following: [https://www.ssc.wisc.edu/~hemken/Stataworkshops/Statamarkdown/including-stata-graphs.html#saving-a-stata-graph](from here)

It would be nice to simplify the process of exporting graphs and including them in the Rmd output. I'd be happy to give it a shot and iterate!

Hemken commented 2 years ago

I’m not sure I understand the question.

The chunk option “echo=1” just shows one line of code in your document.

Or are you asking how to make knitr recognize that a graph has just been saved and display it automatically, like in a Jupyter Notebook or in the stmd package in Stata? If you have a solution for that, I’d be happy to include it.

Doug Hemken

Statistical consultant Social Science Computing Cooperative Univ. of Wisc. – Madison

@.**@.> 608-262-4327

From: Kyle F Butts @.> Sent: Thursday, June 9, 2022 12:43 PM To: Hemken/Statamarkdown @.> Cc: Subscribed @.***> Subject: [Hemken/Statamarkdown] Stata graphics hook (Issue #28)

Is it possible to use a chunk option to plot specific lines of stata code following: [https://www.ssc.wisc.edu/~hemken/Stataworkshops/Statamarkdown/including-stata-graphs.html#saving-a-stata-graph](from here)

It would be nice to simplify the process of exporting graphs and including them in the Rmd output. I'd be happy to give it a shot and iterate!

— Reply to this email directly, view it on GitHubhttps://github.com/Hemken/Statamarkdown/issues/28, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ACYBME2DTT7MEIO2L3YFZ3TVOIUK7ANCNFSM5YK37QVA. You are receiving this because you are subscribed to this thread.Message ID: @.***>

kylebutts commented 2 years ago

Hi Doug,

I think I may have an idea on how to do this with a custom knitr hook. Say you do the following:

```{stata, graph = 1}
graph export scatter.svg, replace


Then you could read the text and parse it with `grepl` and get the name of the file. Then use `knitr::include_graphics("scatter.svg")` automatically. I'll give this a try and see if I can get it to work