Hemken / Statamarkdown

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

`collectcode=TRUE` only works for Rmarkdown documents in the root folder of the project (when chunks are set to evaluate in the root folder) #17

Open DaniMori opened 3 years ago

DaniMori commented 3 years ago

Take the following example, adapted from the Statamarkdown handbook:

---
title: "R Notebook"
output:
  html_document:
    df_print: paged
---

```{r, include=FALSE}
library(Statamarkdown)

A first code block:

sysuse auto
generate gpm = 1/mpg
summarize price gpm

A second, later code block:

regress price gpm


1. Open Rstudio
2. Click on "Tools" -> "Global Options..." -> "R Markdown".
2. In "Evaluate chunks in directory", select "Project" from the dropdown menu, then click "OK"
1. Create a new Rstudio project
2. Save the previous example as a `.Rmd` file in the root folder.
3. Knit the example; everything goes fine.
4. Now create a subfolder (e.g. `notebooks`), and copy the `.Rmd` file into that subfolder.
5. Knit the version of the `.Rmd` file in the subfolder.
6. The second chunk does not run properly, allegedly because `collectcode=TRUE` fails.

A `profile.do` is created in the subfolder and then deleted. However, it might be the case that Stata "looks for" the `profile.do` in the root directory of the project somehow.

Now:

1. Click on "Tools" -> "Global Options..." -> "R Markdown".
2. In "Evaluate chunks in directory", select "Document" from the dropdown menu, then click "OK"

Repeat step 5; the second chunk now runs properly. My guess is that this issue is related to #12 , and most probably to [this response](https://github.com/Hemken/Statamarkdown/issues/12#issuecomment-731277899). However, I think this is a new use case that may help shed some light into the solution.