How to View results in a new window of pipeline without using "%>% View()" or View(pipeline)"?

I trying to run my code which is something like this:

data %>%
function1 %>%
function2 %>%
....

So when I have the mouse pointer at the end of the pipeline and I type ctrl + enter it runs the whole chunk and displays the results in the console which is ok. I want to do the same but I want to display the display the result in a new window as when you do it with View() and I want to do this whenever I want it, I mean it could not be a fixed configuration or something that would take time to change.

For a general solution to this we need some info about the constraints.

  1. Is the data argument known?
  2. Is the pipeline formatted properly (the first line is not indented while the rest of the pipeline is?)

A shortcut addin package is an option. This lets you bind a function that searches for the pipe in the R script, or wherever your cursor is, insert a %>% View() and execute it, with a button press.

shortcut <- function(){
    x <- rstudioapi::getActiveDocumentContext()$contents
    y <- # regular expressions on x to get the pipe content
    rstudioapi::sendtoConsole(code = paste(y,
                                           "%>% View()",
                                           execute = TRUE)
}

if question 2 is true, the regular expression is quite easy, search for the first character string without white spaces at the start.

Here is a nice explanation of a step by step how-to for making your own shortcut

You may find the ViewPipeSteps add-in very useful (which also provide an option to print each pipe step to the console). See this README.md for more details.