1

I have a dataframe in R called df. This is available across all .r files in the R session. I want to knitr some of the results from this dataframe into a .Rmd file. I'm using the following code:

```{r}
names(df)
```

If I highlight and run the line: names(df) within the .Rmd file, it correctly prints out the names of df: [1] "ISIN" "CF" "DATE". But if I click on Knit HTML, it outputs in HTML:

## NULL

How do I get a .Rmd document to access Global Environment variables?

pluke
  • 3,832
  • 5
  • 45
  • 68
  • 3
    I'm not seeing a question, but your observation is correct. Knitting from the console with `knit()`, `knit2html()`, etc., is done within the current R session. Knitting via the RStudio hotkey is done in a fresh R session so it doesn't have access to the global environment from your active session. One way around it is to `save()` objects out and have them `load()` them in your knitr document. – Gregor Thomas May 09 '16 at 16:51
  • Thanks, that explains it: `Knit HTML` button driven .Rmd files cannot access the Global Environment – pluke May 09 '16 at 16:54
  • 1
    Related: http://stackoverflow.com/questions/34591487/difference-compile-pdf-button-in-rstudio-vs-knit-and-knit2pdf – CL. May 10 '16 at 08:12

0 Answers0