library(data.table)
merge_overlaps <- function(tbl, start, end, max_gap = 0) {
grps <- dplyr::group_vars(tbl)
s <- rlang::enexpr(start)
e <- rlang::enexpr(end)
s_nm <- rlang::as_label(s)
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(rstan) | |
| library(bayesplot) | |
| rstan_options(auto_write = TRUE) | |
| options(mc.cores = parallel::detectCores()) | |
| # https://github.com/stan-dev/rstan/wiki/RStan-Getting-Started | |
| stan_code <- ' | |
| data { | |
| int<lower=0> J; // number of schools |
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(lubridate) | |
| library(gganimate) | |
| library(ggfortify) | |
| deaths <- fortify(UKDriverDeaths) %>% | |
| rename(date = Index, deaths = Data) %>% | |
| mutate(year = year(date), month = month(date)) | |
| p <- ggplot(deaths, aes(month, deaths)) + |
library(tidyverse)
library(modelr)
library(splines)
m_ns <- lm(mpg ~ ns(wt, df = 2), data = mtcars)
m_bs <- lm(mpg ~ bs(wt, df = 4), data = mtcars)
pred <- mtcars %>%
data_grid(wt = seq(0, 7, len = 256)) %>% library(tidyverse)
library(fbcutils)
# Produce a grob to be used as for panel backgrounds
guide_grid2 <- function(theme, x.minor, x.major, y.minor, y.major) {
x.minor <- setdiff(x.minor, x.major)
y.minor <- setdiff(y.minor, y.major)library(ggplot2)
library(magick)
#> Linking to ImageMagick 6.9.9.14
#> Enabled features: cairo, freetype, fftw, ghostscript, lcms, pango, rsvg, webp
#> Disabled features: fontconfig, x11
library(grid)
library(gtable)library(tidyverse)
df <- structure(list(foo = structure(c(30L, 15L, 18L, 14L, 50L, 5L,
20L, 22L, 19L, 9L), .Label = c("01", "02", "03", "04", "05",
"06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16",
"17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27",
"28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38",
"39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49",
"50", "51"), class = "factor"), bar = structure(c(10L, 8L, 9L,
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) | |
| add_tdc <- function(df, int, tdc = vars(), event = vars()) { | |
| nm <- names(df) | |
| original_cols <- nm | |
| int <- select_vars(nm, !!!int) | |
| tdc <- select_vars(nm, !!!tdc) | |
| stopifnot(length(int) == 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
| library(microbenchmark) | |
| C_colSums <- function(x) .Call("C_colSums", x) | |
| C_rowSums <- function(x) .Call("C_rowSums", x) | |
| set.seed(1234) | |
| x <- tcrossprod(rnorm(5000)) | |
| dyn.load("matsums.dll") | |
| microbenchmark( |
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
| #define RCPP_ARMADILLO_RETURN_ANYVEC_AS_VECTOR | |
| #include <RcppArmadillo.h> | |
| // [[Rcpp::depends(RcppArmadillo)]] | |
| using namespace Rcpp; | |
| // Cols ---------------- | |
| // [[Rcpp::export]] |