Skip to content

Instantly share code, notes, and snippets.

@bfatemi
Created August 14, 2019 21:47
Show Gist options
  • Save bfatemi/35f112e6d9038a07337c87aa19bd8207 to your computer and use it in GitHub Desktop.
Save bfatemi/35f112e6d9038a07337c87aa19bd8207 to your computer and use it in GitHub Desktop.
set_sample_view <- function(){
selectText <- rstudioapi::primary_selection(rstudioapi::getSourceEditorContext())$text
exprList <- rlang::parse_exprs(selectText)
w <- get("(")
exprDF <- exprList[[which(sapply(exprList, function(x) is.data.frame(w(eval(x)))))]]
invisible(eval(exprDF))
DT <- data.table::as.data.table(w(eval(exprDF)))
vdf <- DT[sample(seq_len(.N), size = min(100, .N), replace = FALSE)]
return(vdf)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment