For a general solution to this we need some info about the constraints.
- Is the
data argument known?
- 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