Hemken / Statamarkdown

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

possible typo in commented out code in find_stata() helpfile example #11

Closed remlapmot closed 4 years ago

remlapmot commented 4 years ago

I was wondering if there might be a small typo in the commented out code in the example on the helpfile for find_stata().

On the line here should #engine.path=stataexe, be replaced with #engine.path = list(stata = stataexe) (as per your code in the Basic Use vignette) for the code to run when not commented out?

When I save the example Rmd code as a separate file and delete the 2 engine.path=stataexe chunk options and click the Knit button in RStudio the current code fails with an error message

Error: $ operator is invalid for atomic vectors
Execution halted

but with the edit it runs.

i.e. edited version is

## Not run: 
indoc <- '
# An R console example
## In a first code chunk, set up with
```{r}
library(Statamarkdown)
stataexe <- find_stata()
knitr::opts_chunk$set(engine="stata", engine.path = list(stata = stataexe),
  error=TRUE, cleanlog=TRUE, comment=NA)

Then mark Stata code chunks with

sysuse auto, clear
generate gpm = 1/mpg
summarize price gpm

A later chunk that depends on the first.

regress price gpm

'

To run this example, remove tempdir().

fmd <- file.path(tempdir(), "test.md") fhtml <- file.path(tempdir(), "test.html")

knitr::knit(text=indoc, output=fmd) markdown::markdownToHTML(fmd, fhtml)



Happy to make a PR if that's easier.
Hemken commented 4 years ago

Thanks for the comment. Sounds like my example has not kept up with changes in knitr and in my code – I’ll have a look.

From: Tom Palmer notifications@github.com Sent: Thursday, October 15, 2020 7:45 AM To: Hemken/Statamarkdown Statamarkdown@noreply.github.com Cc: Subscribed subscribed@noreply.github.com Subject: [Hemken/Statamarkdown] possible typo in commented out code in find_stata() helpfile example (#11)

I was wondering if there might be a small typo in the commented out code in the example on the helpfile for find_stata().

On the line herehttps://github.com/Hemken/Statamarkdown/blob/89ff92fa593c890c8fcb1714c0b10dae0ddbea72/man/find_stata.Rd#L38 should #engine.path=stataexe, be replaced with #engine.path = list(stata = stataexe) (as per your code in the Basic Use vignette) for the code to run when not commented out?

When I save the example Rmd code as a separate file and delete the 2 engine.path=stataexe chunk options and click the Knit button in RStudio the current code fails with an error message

Error: $ operator is invalid for atomic vectors

Execution halted

but with the edit it runs.

i.e. edited version is

Not run:

indoc <- '

An R console example

In a first code chunk, set up with


library(Statamarkdown)

stataexe <- find_stata()

knitr::opts_chunk$set(engine="stata", engine.path = list(stata = stataexe),

  error=TRUE, cleanlog=TRUE, comment=NA)

Then mark Stata code chunks with


sysuse auto, clear

generate gpm = 1/mpg

summarize price gpm

A later chunk that depends on the first.


regress price gpm

'

To run this example, remove tempdir().

fmd <- file.path(tempdir(), "test.md")

fhtml <- file.path(tempdir(), "test.html")

knitr::knit(text=indoc, output=fmd)

markdown::markdownToHTML(fmd, fhtml)

Happy to make a PR if that's easier.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHubhttps://github.com/Hemken/Statamarkdown/issues/11, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ACYBME264E7F7TEFDKHH24DSK3VETANCNFSM4SR6DVYA.

Hemken commented 4 years ago

I've incorporated Tom's fix.