Last active
March 9, 2017 05:00
-
-
Save Keiku/12d00aa201f0e9d38514b8747ef70822 to your computer and use it in GitHub Desktop.
Misc funcions.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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