0

New to markdown and knit, so...
In RStudio, this markdown code does well

## 'r': razão entre opções
```{r}
round(apply(rst0[,c('rstQ','rstV','rstMkt','rstMkt2','rstAntiMkt')],2,mean),3)
```
  rstQ       rstV     rstMkt    rstMkt2 rstAntiMkt 
81.408    111.098      0.012      0.007      0.005 

But when I click knit button, I get error:

Line 20 Error in apply(rst0[,c('rstQ','rstV','rstMkt','rstMkt2','rstAntiMkt')], : object 'rst0' not found Calls: <Anonimous> ... withCallingHandlers  -> withVisible -> eval -> eval  -> apply

But knit('../gap.Rmd') successfully generates the gap.md file.

Waylan
  • 37,164
  • 12
  • 83
  • 109
xm1
  • 1,663
  • 1
  • 17
  • 28
  • 3
    is `rst0` created in the rmarkdown file - if not the code won't be able to find it – Richard Telford May 21 '19 at 17:31
  • 1
    @RichardTelford, all variables must be created in markdown file? Why can markdown find `summary(cars)`? Is it not possible to pass `rst0`to code chunk? Why `knit(..)` works? Sorry for my so little knowledge. – xm1 May 21 '19 at 17:55
  • 4
    `cars` is a built-in R object so it is always available. The knit button renders the rmarkdown in a new environment - no objects are present. knit(...) will run the code from the existing environment so objects can be found. See https://stackoverflow.com/questions/34591487/difference-compile-pdf-button-in-rstudio-vs-knit-and-knit2pdf – Richard Telford May 21 '19 at 18:22
  • I ended up putting an `{r ini, include=F}` chunk that loads the data needed. It seems a good practice. – xm1 May 28 '19 at 20:24

0 Answers0