Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View coolbutuseless's full-sized avatar

mikefc coolbutuseless

View GitHub Profile
@ozjimbob
ozjimbob / rain.r
Last active June 13, 2022 23:54
Raindrops
library(tickle)
x11(type = 'dbcairo', antialias = 'none')
dev.control(displaylist = 'inhibit')
df = data.frame(x=runif(10,-1,1),y=runif(10,-1,1),size=rep(1,10))
size <- reactive_dbl(value=6)
rate <- reactive_dbl(value=10)
# define `makeNamespace` function
eval(body(loadNamespace)[[c(8, 4, 4)]])
ns <- makeNamespace("fake")
# define functions
ns$foo <- function() "foo!"
ns$bar <- function() "bar!"
# export some
@coolbutuseless
coolbutuseless / mutate.listframe
Created April 19, 2021 09:47 — forked from MyKo101/mutate.listframe
Application of the mutate method to a listframe
listframe <- function(...){
structure(
tibble(...),
class = c("listframe","tbl_df","tbl","data.frame")
)
}
lf <- listframe(
a = list(1,c("a","b","c"),matrix(1:4,2,2)),
require(ggplot2)
ggplot() + annotate(x = -10, y=1, xend = -1.38, yend=3, geom='segment', col='white') +
geom_segment(data = data.frame(id=1:30, x = -1.38, y = seq(3.0, 3.0, len=30),
xend = seq(1.1, 1.4, len=30), yend = seq(3.5, 3.0, len=30)),
aes(x, y, xend=xend, yend=yend, col=factor(id))) +
geom_segment(data = data.frame(x = -1.38, y = seq(3.0, 3.0, len=30),
xend = seq(1.4, 1.1, len=30), yend = seq(3.0, 3.5, len=30)),
aes(x, y, xend=xend, yend=yend), col='#00000080') +
geom_segment(data = data.frame(x = -1.38, y = seq(3.0, 3.0, len=30),
  library(anglr)
  dem <- gebco
  mesh <- as.mesh3d(dem, triangles = FALSE)
  mesh$material$color <- colourvalues::colour_values(mesh$vb[3, ]); mesh$meshColor <- "vertices"
  plot3d(mesh)
  rgl::aspect3d(1, 1, .1)
  
  
 ## surface3d way
#remotes::install_cran(c("anglr", "silicate"))

library(silicate)
library(anglr)
library(rgl)
## volcano is heightmap, doesn't exist in geo-space in R so we map it do the extent of
## these spatial polygons 
poly <- silicate::minimal_mesh
# xmin : 0 
@EmilHvitfeldt
EmilHvitfeldt / group_by_in.md
Last active July 16, 2019 16:17
perform overlapping groups with custom grouped data frame
library(tidyverse)
group_by_in <- function(data, x, sep) {
  enquo_x <- rlang::quo_name(enquo(x))
  
  splitted <- strsplit(data[[enquo_x]], sep)
  
  values <- unique(unlist(splitted))
  
 which_list &lt;- function(data, value) {
@MichaelChirico
MichaelChirico / ieee754.R
Created November 27, 2018 15:19
Playing around with IEEE754
ieee754 = function(x, precision = 'long') {
switch(precision, long = {
dig_exponent = 11L
exp_shift = 1023L
dig_mantissa = 52L
}, short = {
dig_exponent = 8L
exp_shift = 127L
dig_mantissa = 23L
}, stop("Valid precisions are 'long' and 'short'."))