What you describe is specific to rmarkdown, and wouldnt be the experience for a
'pure' r script. I believe its more of an rmarkdown/knitr issue than an Rstudio issue.
I found this blog, suggesting the use of the here package :
https://drdoane.com/here-is-your-data/
However, when you knit the document (or spin, or compose notebook… any of the aliases to knitr::knit() and associated functions), the document is evaluated in its own environment. From the perspective of knitr, the base directory is the directory in which you saved the .R, .md, or .Rmd document. Assuming you saved your RMarkdown script in R/ , then knitting that document with the same code as above
I'm wondering whether something like using a normal rscript (that knows the getwd() from the console when its called) and using it to itself knit the markdown doc, passing in the directory to use as a parameter would be a way to go ?