This file contains hidden or 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
| library(tidyverse) | |
| library(rando) | |
| r_mutate <- function(.data,...,.nchars=3){ | |
| nms <- names(.data) | |
| .call <- match.call() | |
| .call[[1]] <- call("::",quote(dplyr),quote(mutate)) | |
| if(".nchars" %in% names(.call)) .call[[".nchars"]] <- NULL | |
| unnamed <- which(names(.call[-1]) == "") | |
| n_vars <- length(unnamed) |
This file contains hidden or 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
| #Overloads the dplyr::filter() function with a chattier version | |
| # provides two nouns for use in the glue-able text, | |
| # .pre is the data before the filtering | |
| # .post is the data after the filtering | |
| filter <- function(.data,...,.chat=NULL){ | |
| this_call <- match.call() | |
| new_call <- this_call | |
| new_call[[1]] <- call("::",quote(`dplyr`),quote(`filter`)) |
This file contains hidden or 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
| na <- function (x) | |
| { | |
| x <- if (missing(x)) { | |
| prev_call <- sys.call(sys.nframe() - 2) | |
| if (identical(prev_call[[1]], quote(if_else)) | | |
| identical(prev_call[[1]], quote(dplyr::if_else))) { | |
| prev_env <- sys.frame(sys.nframe() - 1) | |
| prev_env$x | |
| } | |
| else logical(1) |
This file contains hidden or 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
| ggpipe <- function(data,...){ | |
| len <- ...length() | |
| p <- ggplot(data) | |
| if(len > 0) for(i in 1:len){ | |
| p <- p + ...elt(i) | |
| } | |
| p | |
| } | |
| palmerpenguins::penguins |> |
This file contains hidden or 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
| try_na <- function(...){ | |
| f_list <- purrr::map(list(...),rlang::as_function) | |
| f_len <- length(f_list) | |
| function(.x) { | |
| out <- rep(NA,length(.x)) | |
| i <- 1 | |
| while(any(is.na(out)) & i <= f_len){ | |
| out[is.na(out)] <- f_list[[i]](.x[is.na(out)]) | |
| i <- i + 1 | |
| } |
This file contains hidden or 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
| library(rlang) | |
| library(remotes) | |
| print.historic_defaults <- function(x,...){ | |
| v_list_str <- ls(x) | |
| v_list <- as.numeric_version(v_list_str) | |
| v_list_ordered <- v_list_str[order(v_list)] | |
| for(i in 1:length(v_list_ordered)){ | |
| c_v_list <- v_list_ordered[[i]] | |
| cat("Version:",c_v_list,"\n") |
This file contains hidden or 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
| `[[.data.frame` <- function(x,...,exact=TRUE) { | |
| na <- nargs() - !missing(exact) | |
| if (!all(names(sys.call()) %in% c("", "exact"))) | |
| warning("named arguments other than 'exact' are discouraged") | |
| if (na < 3L) | |
| { | |
| (function(x, i, exact) | |
| { | |
| if (is.matrix(i)) | |
| { |
This file contains hidden or 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
| pseudosurv2 <- function (time, event, tmax) | |
| { | |
| if (any(is.na(time))) | |
| stop("missing values in 'time' vector") | |
| if (any(time < 0)) | |
| stop("'time' must be nonnegative") | |
| if (any(is.na(event))) | |
| stop("missing values in 'event' vector") |
This file contains hidden or 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
| mutate_where <- function(x,predicate,...){ | |
| full_x <- mutate(x,..row_ids = 1:n()) | |
| .predicate <- enquo(predicate) | |
| predicated_x <- filter(full_x,!!.predicate) | |
| other_x <- filter(full_x,!(!!.predicate)|is.na(!!.predicate)) | |
| mutated_x <- mutate(predicated_x,!!!enquos(...)) |
This file contains hidden or 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
| #install.packages(here) | |
| #install.packages(crayon) | |
| p <- function(str){ | |
| structure(str,class=c("path","character")) | |
| } | |
| `/.path` <- function(a,b){ | |
| p(paste(a,b,sep="/")) | |
| } |