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
obj_size <- function(obj, units = 'Mb') { | |
dimensions <- dim(obj) | |
data.frame( | |
rows = format(dimensions[1], big.mark = ","), | |
columns = format(dimensions[2], big.mark = ","), | |
size = format(object.size(obj), units = units, big.mark = ",") | |
) | |
} |
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
DECLARE dataset_names ARRAY<STRING>; | |
DECLARE batch ARRAY<STRING>; | |
DECLARE batch_size INT64 DEFAULT 25; | |
CREATE TEMP TABLE results ( | |
project_id STRING, | |
dataset_id STRING, | |
last_modified DATE, | |
table_id STRING, | |
row_count INT64, |
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
snippet ggstuff | |
labs(title = "${1:title}", | |
subtitle = "${2:subtitle}", | |
x = "${3:xlab}", | |
y = "${4:ylab}") + | |
theme_minimal() | |
snippet gglabs | |
labs(title = "${1:title}", | |
x = "${2:xlab}", |
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
#' Sample groups randomly in a grouped data frame | |
#' | |
#' @param .data dataframe | |
#' @param ... names of key variables to define groups. If unspecified, dataframe must be grouped. | |
#' @param n if integer, number of unique groups to keep. If between 1 and 0, proportion of unique groups to keep. | |
#' | |
#' @return tibble of all rows for sampled groups | |
#' @export | |
#' | |
#' @examples |
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
#' Scale a Variable Between a Given Min and Max | |
#' | |
#' @param x values to be scaled | |
#' @param new_min new minimum value | |
#' @param new_max new maximum value | |
#' | |
#' @return an object of the same class as `x` | |
#' @export | |
#' | |
#' @examples |
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
#' symlog transformation | |
#' | |
#' `symlog_trans()` transforms data using `log(x)` for `abs(x) > thr`, where | |
#' `thr` is a tuneable threshold, but leaves the data linear for `abs(x) < thr`. | |
#' (credit for base code to https://stackoverflow.com/users/1320535/julius-vainora) | |
#' | |
#' | |
#' @param base base of logarithm | |
#' @param thr numeric threshold for transitioning from log to linear | |
#' @param scale numeric scaling factor for data |
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
-- implementation | |
WITH input AS ( | |
SELECT * | |
FROM UNNEST([100,100,100,100,100,100,100,100,100,100]) x | |
JOIN UNNEST([.4,.4,.4,.4,.4,.4,.4,.4,.4,.4]) p | |
) | |
SELECT x * (1 + (-p + (RAND() * (2 * p)))) AS rand_within_p_percent_of_x | |
FROM input; | |
-- verification of concept |
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
sapply(list.files("R/", full.names = T), source) |
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
copy_to_gcp <- function(.data, filename_prefix, gcp_folder = NULL, gcp_bucket) { | |
if (!startsWith(gcp_bucket, "gs://")) { | |
gcp_bucket <- paste0("gs://", gcp_bucket) | |
} | |
source <- paste0(filename_prefix, "_", format(Sys.Date(), "%Y%m%d"), ".csv") | |
destination <- ifelse(is.null(gcp_folder), gcp_bucket, paste0(gcp_bucket, "/", gcp_folder)) | |
packageStartupMessage("Writing file") | |
write.csv(.data, source) |
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
## Plumber-verse Base Image ##################### | |
FROM rocker/verse | |
RUN apt-get update -qq && apt-get install -y \ | |
git-core \ | |
libssl-dev \ | |
libcurl4-gnutls-dev | |
## Install Plumber |
NewerOlder