1

I'm working in RStudio and prefer having a full-window editor separate from the console. By default, when I run:

file.edit(c("script1.R", "script2.R"))

The files open as tabs in the docked Source pane of RStudio. Although I can manually detach the Source pane (or move an individual file to a new window), each new file still opens in the docked pane by default. This forces me to manually reassign each file to my separate editor window...

Is there a configuration option in RStudio to force all files opened via file.edit() to automatically appear in a separate, undocked window (or a single detached window with multiple tabs)?

If no such built-in option exists, what workarounds are available? Would switching to an external editor (or setting one via options(editor=...)) be a viable alternative, and what external editors integrate well with R for this purpose?

I've reviewed the Global Options and Pane Layout settings but haven’t found a way to influence this behavior directly for file.edit().

1 Answer 1

1

How about using the rstudioapi first for navigating to the file and then call popoutDoc. You can also adapt this to only popout once and open the remaining Scripts within the same opened window in new tabs.

library(rstudioapi)

launch_detached <- function(files) {
  for (file in files) {
         navigateToFile(file)
         executeCommand("popoutDoc", quiet = FALSE)
       }
  }
 
launch_detached(c("script1.R", "script2.R"))

Notes

  • you can also overwrite file.edit with above function or even define it in your RProfile so it stays permanent
  • I don't know of any global option to do the same
  • have not looked into positioning these newly opened windows so this can be improved.

Opening files in other editors e.g. notepad

You can also use processx to open files in other editors. Here use any other IDE you seem fit for your task that ideally does not use tabs. Notepad is just an example.

library(processx)

open_in_notepad <- function(files) {
  notepad_path <- "C:/Windows/system32/notepad.exe"  
  for (file in files) {
    file_path <- normalizePath(file, mustWork = FALSE)
    process$new(notepad_path, args = c(file_path), cleanup = FALSE)
  }
}

open_in_notepad(c("script1.R", "script2.R"))

Results

out

Sign up to request clarification or add additional context in comments.

1 Comment

Hello Tim ! Thank you for your answer, I used the first part of the answer to solve my problem. I'll also give a try to the second one, see if it can benefit my workflow.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.