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
## Modify a vector in the workspace; x is a user-accessible symbol | |
x <- 42 | |
.Internal(inspect(x)) | |
# @5631a3a19e20 14 REALSXP g0c1 [REF(5)] (len=1, tl=0) 42 | |
x[1] <- 43 # modification causes a copy (address changes) | |
.Internal(inspect(x)) | |
# @5631a36c1cb8 14 REALSXP g0c1 [REF(4)] (len=1, tl=0) 43 | |
## Modify a vector inside a function; user cannot access y | |
f <- function() { |
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
module Change (findFewestCoins) where | |
import Data.List (find) | |
import Data.List (minimumBy) | |
import Data.Function (on) | |
import Debug.Trace | |
smallestLengthList :: [[Integer]] -> [Integer] | |
smallestLengthList = minimumBy (compare `on` length) |
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(shiny) | |
ui <- fluidPage( | |
titlePanel("Expand/Collapse DataTable"), | |
mainPanel( | |
fluidRow( | |
column(6, DT::dataTableOutput("tbl")), | |
column(6, DT::dataTableOutput("tbl2")) | |
) | |
) |
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
dbg <- function(x) { | |
ex <- rlang::f_text(rlang::enquos(x)[[1]]) | |
ret <- rlang::eval_bare(x) | |
message(glue::glue("DEBUG: {ex} = {ret}")) | |
ret | |
} | |
a <- 1 | |
b <- 3 | |
x <- dbg(a + b) |
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://notstatschat.rbind.io/2022/11/03/improving-a-graph/ | |
d <- read.table( | |
"https://gist.githubusercontent.com/tslumley/9ac8df14309ecc5936183de84b57c987/raw/9ebf665b2ff9a93c1dbc73caf5ff346909899827/busdata.txt", | |
header = TRUE | |
) | |
d$date <- as.Date(paste(2022, d$mo, d$d, sep = "-")) | |
d$weekend <- with(d, weekdays(d$date) %in% c("Saturday", "Sunday")) | |
d$workday <- with(d, !(weekdays(date) %in% c("Saturday", "Sunday"))) |
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
splt <- function(s) { | |
x <- strsplit(s, "-") | |
s[order(sapply(x, `[[`, 1), as.integer(sapply(x, `[[`, 2)))] | |
} | |
splt_radix <- function(s) { | |
x <- strsplit(s, "-") | |
s[order(sapply(x, `[[`, 1), as.integer(sapply(x, `[[`, 2)), method = "radix")] | |
} |
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
## Goal: reproduce e.g. https://www.reddit.com/r/oddlysatisfying/comments/uc054a/lissajous_polygons | |
using Plots | |
import GeometryBasics: Point | |
## https://jcarroll.xyz/2022/04/07/interpolation-animation-in.html | |
interpolate(a, b) = t -> ((1.0 - t) * a + t * b) | |
## define the vertices of an N-gon |
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
starts_with_ordered <- function(match, decreasing = FALSE) { | |
all_vars <- tidyselect::peek_vars() | |
matches <- tidyselect::starts_with(match) | |
named_matches <- setNames(matches, all_vars[matches]) | |
named_matches[order(names(named_matches), decreasing = decreasing)] | |
} | |
mtcars |> | |
dplyr::select(starts_with_ordered("c", decreasing = FALSE)) |> | |
head() |
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(SummarizedExperiment) | |
## create a SummarizedExperiment | |
se <- SummarizedExperiment(assays = | |
list( | |
counts = matrix(0:99, 10, 10), | |
cpm = matrix(200:299, 10, 10) | |
) | |
) | |
## add tabular metadata with assay-specific properties |