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(DeclareDesign) | |
| library(tidyverse) | |
| library(geomtextpath) | |
| design_1 <- | |
| declare_model(N = 1000, | |
| U = rnorm(N), | |
| Y_Z_0 = U, | |
| Y_Z_1 = U + 0.2) + | |
| declare_assignment(Zk = complete_ra(N = N, num_arms = k)) + |
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
| # adapted from https://glin.github.io/reactable/articles/cookbook/cookbook.html#nested-tables | |
| library(dplyr) | |
| data <- MASS::Cars93[18:47, ] %>% | |
| mutate(ID = as.character(18:47), Date = seq(as.Date("2019-01-01"), by = "day", length.out = 30)) %>% | |
| select(ID, Date, Manufacturer, Model, Type, Price) | |
| sales_by_mfr <- group_by(data, Manufacturer) %>% | |
| summarize(Quantity = n(), Sales = sum(Price)) |> |
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(sf) | |
| library(readxl) | |
| library(janitor) | |
| library(rmapshaper) | |
| library(tigris) | |
| library(tidycensus) | |
| library(tidyverse) | |
| library(furrr) | |
| library(here) |
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
| # See `curl.md`. Here is the R equivalent. | |
| library(httr) | |
| library(jsonlite) | |
| make_page <- function(url, headers, data) { | |
| response <- POST( | |
| url = url, | |
| body = toJSON(data, auto_unbox = TRUE), | |
| config = add_headers(.headers = headers) |
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
| # https://stackoverflow.com/a/70956247/6702544 | |
| ``` r | |
| # use functions from the | |
| # tidyr, stringr and purrr packages | |
| library(tidyverse) | |
| # create fake dataset | |
| expand_grid(cat = c("a","b"), | |
| lev = "c", | |
| num = 1:2) %>% |
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
| [ | |
| "FCi27mtaKod38ztmGndn-y8NNz.r.lt6SndqGztz_ztr-ngqQm9aMo9eOnMeJntuNntu", | |
| "D2ei2mgqJz9b-m.mGmPqRyLNNnwmOlt7.ywiGmt-Kndr9otqRywv8o9ePmtiNmd2Sn92Tma", | |
| "6U7vcmPuOn9uLnMaGyM7-nLNNntv9lt6RmtaGmweOyMmJnMmSmgmOo9eOnM6LnMaRmM-Tma", | |
| "lXLf8owyQztiMzwqGnMz7zcNNotb7lwf.m9qGzt6Km.qMngqLndqLo9eOotaNm96Mmt6Tma", | |
| "FCi27y9qOnd-Ny96GmPmOmcNNzwf-lwj-m9mGztz7ytaMnM78n9v-o9ePmM6Rm9-Qn9eTma", | |
| "XlEDumMz7nM7-m9iGogmRmLNNyt_8lwiKz9eGm9-Pm.v7ztiLztz_o9eOnMeQnd-Sodm", | |
| "lXLf8yt-JywmNmPeGm9n9n8NNzgn.lt_8zwqGogz7zgn7zt6SyPr-o9eOnM6Pot2Mn9qTma", | |
| "FCi27zgf8mdqMmMeGnMmMy8NNz9eQlweNy.eGmMiMm96Qmgr9nMb-o9ePmtuRmt6JotmTma", | |
| "FCi27nwmKnMeSodeGm.z.y8NNntz.lt-PywmGy9__ngqQmtiPmtb7o9ePmteJotyJoduTma", |
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
| .First <- function(){ | |
| # adapted from: https://lapsedgeographer.london/2020-11/custom-r-prompt/ | |
| my_prompt <- function(...) { | |
| git_branch <- suppressWarnings(system("git rev-parse --abbrev-ref HEAD", | |
| ignore.stderr = TRUE, intern = TRUE)) | |
| if (length(git_branch) != 0) { | |
| git_msg <- paste0(" @", git_branch) |
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) | |
| # based on {searchable} and https://stackoverflow.com/a/64931927/3246758 | |
| # stats::setNames is fine too! | |
| invert <- function(x) { | |
| set_names(names(x), x) | |
| } | |
| # let's map the coded names to our friendly ones! | |
| fruit <- c( |
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
| --- | |
| title: "Fancy math" | |
| output: | |
| html_document: default | |
| pdf_document: default | |
| --- | |
| ```{r setup, include=FALSE} | |
| # Conditional tikz output types; use PDF if this is LaTeX, otherwise use a | |
| # shrunken down high resolution PNG |
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
| ## ----setup,include=FALSE,message=FALSE,warning=FALSE----------------------------------------------------------------------------------------------------------------------------------------------------- | |
| library("here") # 1.0.1 | |
| library("sf") # 1.0-14 | |
| library("rgl") # 1.2.1 | |
| library("geoviz") # 0.2.2 | |
| library("raster") # 3.6-26 | |
| library("rayshader") # 0.35.7 | |
| library("osmdata") # 0.2.5 | |
| library("tidyverse") # 2.0.0 |