knitting directory conflicts

My RMD file is in cloud/project/hw
The data file is in cloud/project/data

Confusingly, when working interactively I have to use
data <- read.delim("data/data.txt")

but when I knit, I have to use
data <- read.delim("../data/data.txt")

Why is there a discrepancy and how can I resolve it?

In the interactive console, the current working directory, by default, is /cloud/project.
However, when you knit a file in a subdirectory, the context for knitting is that subdirectory, and thus you need the relative path.
Hope that helps!

Right... So then basically using setwd() in the RMD file is going to be the only way to ensure that the directories are the same.

Context: I'm teaching a set of students some minimal basics on how to use R for some data analysis, and am trying not to get into complex details such as paths. I know that may seem trivial, but that is one of the biggest sticking points that i've encountered with teaching students R.