R - Knitr script not setting correct WD using opts_knit$set command

105 Views Asked by At

So, I have a directory that is set up as follows:

Main Directory

Scripts

RmdOutputs

RawData

Dataset1

Dataset2

And my goal is to create an Rmd document that is capable of reading Raw Data. However, I run into an issue when my Rmd chunks don't seem to recognize the right Working Directory. I originally was running with the setwd() command, but that proved useless in Rmd.

So I googled a bit, and found that there's a separate command option for Rmds about reading WDs for code chunks.

```{r load_requirements, echo=FALSE, message=FALSE, warning=FALSE}

## Establish Libraries
library(dplyr)
library(knitr)
library(ggplot2)
library(DT)

## Set Working Directory
opts_knit$set(root.dir = "C:/MainDirectory")

## Read Data
indata <- read.csv(file.choose())
```

This code does not function, and still attempts to pull the WD as my RmdOutputs folder. I'm sorry to ask this as such a crude question, but what have I done wrong so that my script isn't pulling its indata from the correct source?

0

There are 0 best solutions below