posit-dev / posit-dev/positron
Use `chdir = TRUE` when sourcing R scripts
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 4.3k
- Forks
- 184
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 206
Description
System details:
Positron and OS details:
Positron Version: 2025.03.0 build 46
Code - OSS Version: 1.96.0
Commit: 99f36c653f7570b325f6f9f8712052405a05426f
Date: 2025-02-18T23:38:56.252Z
Electron: 32.2.6
Chromium: 128.0.6613.186
Node.js: 20.18.1
V8: 12.8.374.38-electron.0
OS: Darwin arm64 24.3.0
Interpreter details:
any
Describe the issue:
R scripts are sourced in the current working directory.
Steps to reproduce the issue:
- Open an .R file in Positron
- Change to a directory other than the one in which the .R file resides, e.g.
setwd("~") - Add the following to the file:
print(getwd()) - From the Command Palette, run the R: Source R File command (Cmd + Shift + S)
The script prints the current directory, not the directory of the script.
Expected or desired behavior:
The script should be run in the context of its own directory -- like notebooks, scripts are easier to write when they're run in a predictable working directory. We could use the chdir = TRUE argument to R's source() command to accomplish this.
This behavior should probably be optional since there are likely cases where you want a script to run against your current directory.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the implementation of the Command Palette's “R: Source R File” command and trace how it invokes R's source() function. Check for existing tests around sourcing scripts; done means sourcing an .R file uses its own directory by default while preserving a clearly defined way to use the current working directory.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- r, typescript
- Domain
- developer-experience, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100