Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Add function for source file location #277

Open
rjake opened this issue Jun 21, 2023 · 0 comments
Open

Feature Request: Add function for source file location #277

rjake opened this issue Jun 21, 2023 · 0 comments

Comments

@rjake
Copy link

rjake commented Jun 21, 2023

I use the menu option "Session > Set Working Directory > To Source File Location" a ton and have started using this programmatically via
setwd(dirname(rstudioapi::getSourceEditorContext()$path))
or
setwd(dirname(.rs.api.getSourceEditorContext()$path))

I'm curious if there could be a shorter command that mimics the Session menu option:
rstudioapi::setwdToSoureFileLocation()
or
setwd(rstudioapi::getSoureFileLocation())

The top two are fine, they are just verbose and I often have to look it up... "right, sourceEditor not activeDocument ... oh yeah, add $path ... oh right, I need dirname()"

I know it's been said not to use setwd() in your code but we use github a ton and I don't always want to create a .Rproj for a simple .R + .csv combo. Anyone (mostly me) who has cloned a repo and opened a file should be able to set their working directory to that file's location.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant