-
Notifications
You must be signed in to change notification settings - Fork 138
Description
Describe the bug
Working with R Markdown, I read data and sourced scripts from other folders. I work from a root folder, which contains the sub-folders /scripts and /data, and I need to specify relative paths to import my data and source other R scripts. The problem seems to be that the working directory differs between Run chunk and Knit Rmd. Running chunks seem to assume my working directory is /root, whereas Knit uses /scripts (when the script I'm using is located in that folder). I have a feeling it might be myself having missed a setting somewhere, regardless any help would be appreciated. FYI I'm quite new to VS Code, but have already gotten a good working setup with radian, httpgd, etc.
To Reproduce
Steps to reproduce the behavior:
- Set up folder structure:
Root folder
| -- scripts
| + -- `Test.Rmd`
| + -- `helper_functions.R`
| -- data
- Create a test
Test.Rmdscript and save in/scripts:
---
title: "Test"
author: "John Doe"
date: "2/8/2021"
output: html_document
---
```{r setup}
source("scripts/helper_functions.r")
(Can't close the R chunk here, but insert ticks yourself)
- Create
helper_functions.Rin/scripts, e.g. containing:
sq <- function(x){
return(x^2)
}- Open
Test.Rmd - Run chunk - works fine, our function
sqshows up in the R Workspace. - Knit document
- See error:
Quitting from lines 9-10 (Test.rmd)
Error in file(filename, "r", encoding = encoding) :
cannot open the connection- Remove
scripts/fromTest.Rmd:
source("helper_functions.r")
- Document knits well, but now
Run chunkdoesn't work
Do you want to fix by self? (We hope your help!)
If easy, yes.
setting.json
// R path for Mac OS X
"r.rterm.mac": "/Users/username/opt/anaconda3/bin/radian",
// Use bracketed paste mode
"r.bracketedPaste": true,Expected behavior
Running code chunks and knitting should exhibit the same behaviour - otherwise one will have to change the paths every time before knitting.
Environment (please complete the following information):
- OS: macOS Big Sur
- VSCode Version: 1.60.0-insider
- R Version: 4.1.0
- vscode-R version: 2.1.0