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
library(glue) | |
library(RPostgreSQL) | |
library(DBI) | |
drv <- dbDriver("PostgreSQL") | |
con <- dbConnect(drv, | |
host=Sys.getenv("JDBCURL"), | |
port = Sys.getenv("PORT"), | |
dbname = Sys.getenv("DBNAME"), | |
user = Sys.getenv("USER"), |
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
--- | |
title: "Plotly and floating TOC" | |
output: | |
html_document: | |
toc: true | |
toc_float: true | |
--- | |
# h1 |
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
``` r | |
# tidyeval for multiple arguments that can take multiple variables | |
library(dplyr) | |
# in the case where the verbs' arguments are ... e.g. group_by(), select(), use !!! within the function to expand the variables back out | |
# no enquo() or enquos() is needed because you will pass in a vars() call | |
group_select <- function(df, group_vars, select_vars){ | |
df %>% |
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
not_equal <- function(a, b){ | |
ifelse(a != b | is.na(a) | is.na(b), | |
ifelse(is.na(a) & is.na(b), | |
NA, | |
TRUE), | |
FALSE) | |
} | |
not_equal("A", "A") | |
#> [1] FALSE |
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(shiny.reactlog = TRUE) | |
library(shiny) | |
library(reactlog) | |
mod_iris_ui <- function(id) { | |
ns <- NS(id) | |
tagList( | |
fluidRow( | |
column( |
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
# Deriving the "overall working status" of someone's employment positions | |
# in Ontario, where it is the highest of Full Time > Part Time > Casual. | |
# e.g. if someone has a full time and a part time position, their overall | |
# working status is full time. If they have two part time positions, it's part time. | |
library(dplyr) | |
sample_df <- tibble::tribble( | |
~id, ~working_status, ~province, | |
1, "Full Time", "Ontario", | |
1, "Casual", "Ontario", |
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
library(tibble) | |
library(tidyr) | |
x <- tibble(a = 1, | |
b = 1:2, | |
c = 3:4) | |
x | |
#> # A tibble: 2 x 3 | |
#> a b c |
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
library(httr) | |
library(dplyr) | |
resp <- GET("https://summary-api.datamermaid.org/v1/sites/") | |
content <- jsonlite::fromJSON(content(resp, "text", encoding = "UTF-8"), simplifyDataFrame = TRUE) | |
as_tibble(content[["features"]]) |
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
library(ggplot2) | |
plot_diamonds <- function() { | |
p <- ggplot(head(diamonds), aes(x = cut, y = price)) + | |
geom_jitter() | |
res <- list( | |
name = "diamonds", | |
p = p | |
) | |
class(res) <- "diamonds" |
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
sharla_diff <- function(df, expected_df) { | |
data_as_expected <- dplyr::all_equal(expected_df, df) | |
if (!isTRUE(data_as_expected)) { | |
data_diffs <- janitor::compare_df_cols(expected_df, df) | |
cols_mismatch <- dplyr::filter(data_diffs, is.na(expected_df) | is.na(df)) | |
extra_cols <- cols_mismatch %>% | |
dplyr::filter(is.na(expected_df)) %>% |
OlderNewer