I have an R code that generates several plots and tables from my data. I want to write a report in Rmarkdown in which i want to include just the plots and the tables without rewriting the R code. One way is to use 'read_chunk' function but it does not serve my purpose. Following is a simple example of what i need.
Suppose I have the following R script 'Example.r'
x <- 1:4
y <- sin(x)
####----Table
table <- cbind(x,y)
####----Plot
plot_1 <- plot(x,y)
Now in my R markdown file i want the following:
```{r echo=FALSE, cache=FALSE}
knitr::read_chunk('Example.r')
```
The following table shows the results:
```{r Table, echo=FALSE}
```
One can depict the result in a plot as well:
```{r Plot, echo=FALSE}
```
In the above example, i will not be able to insert either the table or the plot, since both need the input 'x' and 'y' to be defined before the table and the plot commands are run. Is there a way to implement this without hardcoding 'x' and 'y' two times?