Keiku
1/26/2017 - 6:12 AM

Misc funcions.

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="")
}