#' Automatically recognize the clipboard or selected line
#' @author Jiaxiang Li
#'
#' @import rstudioapi
#' @import clipr
select_lines <- function(){
rstudioapi::getSourceEditorContext() %>%
rstudioapi::primary_selection() %>%
.[["text"]]
}
selected <- function(){
raw_line <- select_lines()
clipboard <-
clipr::read_clip() %>%
str_flatten('\n')
# read_clip will seperate the lines.
line <-
if (raw_line=='') {
clipboard
} else {
raw_line
}
return(line)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.