Make R's View() open in a new window automatically

半腔热情 提交于 2019-12-04 22:59:51

You could consider overwriting the viewer options.

options(viewer = function(url, height = NULL)
{
  if (!is.character(url) || (length(url) != 1))
    stop("url must be a single element character vector.", call. = FALSE)

  if (identical(height, "maximize"))
    height <- -1

  if (!is.null(height) && (!is.numeric(height) || (length(height) != 1)))
    stop("height must be a single element numeric vector or 'maximize'.", call. = FALSE)

  invisible(.Call("rs_showPageViewer", url, title = "RStudio", self_contained = FALSE))  
})

Explanation:

The code of viewer options can be found here: https://github.com/rstudio/rstudio/blob/master/src/cpp/r/R/Options.R.

Your desired functionality (open in new window) is the page_viewer, see here: https://github.com/rstudio/rstudio/blob/779baf9ceb99b6d2455345bcbae3c4e57e164425/src/cpp/r/R/Options.R#L45

The current default behaviour is to open viewer not page_viewer. The code of the viewer option is here https://github.com/rstudio/rstudio/blob/779baf9ceb99b6d2455345bcbae3c4e57e164425/src/cpp/r/R/Options.R#L28.

It is a bit hacky, but you could overwrite the viewer option and let it open a new window instead of displaying the content in the viewer pane, see my code snippet above.

Integrate it in your workflow:

(Note that running the code above will only yield the desired functionality during the current session. Running it each time upon starting a new session would be too much effort).

  1. If you are sure you never want to use the viewer pane again, you could consider using the code above and place it in your .RProfile Locate the ".Rprofile" file generating default options. I did not find out yet how to do this as "rs_showPageViewer" is not a method of the base namespace (?). Not sure how to reference the method,... [could make an edit, if you prefer this option].

  2. Write a small addin. Downside that it is kind of an overkill to introduce an extra addin for this. Upside would be that you can change in between both options (window vs. pane) during one session via click / keyboard shortcut.

Addin:

I uploaded it on my github: https://github.com/Timag/viewerWindow.

Install per devtools::install_github('Timag/viewerWindow').

And then select the addin

  • ViewerWindow: Open all viewer in new window from now on.

  • ViewerPane: Open all viewer in new pane from now on.

or assign keyboard shortcuts to it.

Edit 11.2019:

(this little hack might not work anymore - see https://github.com/Timag/viewerWindow/issues/1)

PsychometStats

This opens data frame in a new window right away:

edit(df) 
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!