3

I am trying to programmatically set directory in the Files tab within RStudio. The version of RStuido is 1.1.453. I have tried looking within rstudioapi package but the relevant functions that I found selectDirectory() and selectFile() open an interactive file tree browser and they do not change the Files tab content. I know that one can use setwd() then in the Files tab use More -> Go To Working Directory but I need to do this fully programmatically.
In summary I wish there was a function setFilesTab(dirpath = ) which I could submit and the Files tab would change the focus to the dirpath.

Thank you so much for your help and time!

Edgar Manukyan
  • 1,153
  • 10
  • 21
  • 1
    https://github.com/rstudio/rstudioapi/issues – MichaelChirico Aug 02 '18 at 02:49
  • it looks like `selectFile` has a `path` argument? https://github.com/rstudio/rstudioapi/blob/e87b481fee0f156015f8c834d8faf2c9f36a6aa6/R/stubs.R#L175-L182 – MichaelChirico Aug 02 '18 at 02:52
  • 1
    Thank you @MichaelChirico, the both `selectFile()` and `selectDirectory` have `path` argument and it is used as a starting point for the interactive file browser. Unfortunately this has no efffect on Files tab within RStudio. I guess you are alluding to open a feature suggestion in GitHbub repo for `rstudioapi` package. – Edgar Manukyan Aug 02 '18 at 03:28
  • `rstudioapi::filesPaneNavigate()` should do the trick! – RoyalTS Apr 29 '21 at 08:50

1 Answers1

2

This is my first post on this website; so, hello to all.

I am excited to be part of this community.

Just adding to the answer by RoyalTS, I wanted to specifically tell the files tab to open the working directory. This code works:

rstudioapi::filesPaneNavigate(getwd())

Cheers,

Jason