Skip to content

Feature Request: Add function for source file location #277

Open

Description

@rjake

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions