1
votes

I making a blog where I try to apply an ARIMA model. Each chunk consists of one step in the data preparation. The final step is to plot the data. However, I cannot for the life of my get the last chunk to use data from previous chunks.

I've tried cache=TRUE both global and local. I've tried ref.label and dependson. Not matter what it doesnt work. The source ode doesn't include any CACHE commands, but I've tried.

```{r packages, message=FALSE}
library(quantmod)
library(tseries)
library(timeSeries)
library(forecast)
library(xts)
```

### Data Preparation

Time to pull the data. This line of code pulls daily prices including volume.
```{r pull, message=FALSE, eval=FALSE}
getSymbols('DANSKE.CO', from='2014-08-01', to='2019-08-01', src = 'yahoo')
```

I'm only going to use the adjusted close price. I simply reassign the Dansk Bank variable to only contain the adjusted close data.
```{r clean, message=FALSE, eval=FALSE}
DANSKE.CO <- DANSKE.CO[,4]
```

Next I'm transforming the prices by taking the log. This can help achieve lower variance before the differencing. Furthermore, much finance litterature often assumes prices are log-normal distributed and I'm no position to question the status quo right now.  
```{r log, message=FALSE, eval=FALSE}
DANSKE.CO <- log(DANSKE.CO)
```

Finally I'm interested in the log-returns not log-price. 
```{r returns, message=FALSE, eval=FALSE}
DANSKE.CO <- diff(DANSKE.CO, lag=1)
DANSKE.CO <- DANSKE.CO[!is.na(DANSKE.CO)] #Removes the first row since it does not contain the daily return.
```


Alright. Let's look at the data.
```{r plot_data, echo=FALSE, message=FALSE}
plot(DANSKE.CO, main='Danske Bank')
```

Error in plot(DANSKE.CO, main = "Danske Bank") : 
  object 'DANSKE.CO' was not found
Call: local ... withCallingHandlers -> withVisible -> eval -> eval -> plot
1
Where exactly do you create DANSKE.CO as an object in R's .GlobalEnv? Plus you have eval = FALSE everywhere. - Grada Gukovic
Me adding eval = FALSE was the culprit. Thanks! - NotPzl

1 Answers

1
votes

As indicated in the comments, the problem is likely resulting from the use of the eval = FALSE chunk option.

DANSKE.CO is not being created/modified in your R Markdown chunk because you are using the eval = FALSE chunk option. The eval = FALSE option tells the R Markdown document to not run the code within the chunk. Removing these settings from your chunks will most likely fix your problem.

See Chapter 2.6 from Yihui Xie's R Markdown book a more in depth explanation of R Markdown options from the author of the package.

https://bookdown.org/yihui/rmarkdown/r-code.html