Skip to content

Instantly share code, notes, and snippets.

@Keiku
Last active March 9, 2017 05:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Keiku/12d00aa201f0e9d38514b8747ef70822 to your computer and use it in GitHub Desktop.
Save Keiku/12d00aa201f0e9d38514b8747ef70822 to your computer and use it in GitHub Desktop.
Misc funcions.
options(scipen = 100, dplyr.width = Inf, dplyr.print_max = Inf)
'%nin%' <- Negate('%in%')
keep_vecs <- function(x, y) x[x %in% y]
drop_vecs <- function(x, y) x[!x %in% y]
keep_vars <- function(.data, x) dplyr::select_(.data, .dots = x)
drop_vars <- function(.data, x) dplyr::select(.data, -one_of(x))
intersect_all <- function(...) Reduce(intersect, list(...))
union_all <- function(...) Reduce(union, list(...))
add_backquotes <- function(x) paste0("`", x, "`")
add_doublequotes <- function(x) paste0("\"", x, "\"")
generate_c_code <- function(x){
vec <- paste0(add_doublequotes(x), sep=",\n")
vec_tail <- str_replace(tail(vec, 1), ",\n", "\n")
vec_head <- head(vec, length(vec) - 1)
vec <- c(vec_head, vec_tail)
cat("c(\n", vec, ")", sep="")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment