Reputation: 1170
This seems simple but I can't get my head around why it isn't working... I have a Rmarkdown file(test.Rmd) in which I'm sourcing an R file(test1.R), the code in sourced R file doesn't seem to access the objects in Rmarkdown file - why?
content of test.Rmd :
---
title: "Test"
runtime: shiny
output: html_document
---
```{r echo=FALSE,results='asis',message=FALSE}
library(data.table)
x<-data.table(a=1,b=2)
source("test1.R")
{knitr::kable(x1)}
```
Content of test.R
x1<-x
The error while running the document is :
Error : Object 'x' not found
Why doesn't sourced commands couldn't access the objects in the calling scope?
Upvotes: 2
Views: 990