Statamarkdown icon indicating copy to clipboard operation
Statamarkdown copied to clipboard

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

Open DaniMori opened this issue 3 years ago • 0 comments

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:

```{stata first-Stata, collectcode=TRUE} 
sysuse auto
generate gpm = 1/mpg
summarize price gpm
```

A second, later code block:

```{stata second-Stata} 
regress price gpm
```
  1. Open Rstudio
  2. Click on "Tools" -> "Global Options..." -> "R Markdown".
  3. In "Evaluate chunks in directory", select "Project" from the dropdown menu, then click "OK"
  4. Create a new Rstudio project
  5. Save the previous example as a .Rmd file in the root folder.
  6. Knit the example; everything goes fine.
  7. Now create a subfolder (e.g. notebooks), and copy the .Rmd file into that subfolder.
  8. Knit the version of the .Rmd file in the subfolder.
  9. 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. However, I think this is a new use case that may help shed some light into the solution.

DaniMori avatar May 05 '21 13:05 DaniMori