Skip to content

Instantly share code, notes, and snippets.

View lgatto's full-sized avatar

Laurent Gatto lgatto

View GitHub Profile
## l1 is a list with 20 numeric elements of length 1e4 each
set.seed(123)
l2 <- l1 <- replicate(20,rnorm(1e4),simplify=FALSE)
length(l1)
sapply(l1,length)
## l2 is the same list with names
names(l2) <- paste0("X", 1:length(l2))
@lgatto
lgatto / insert-code-chunk.el
Last active January 7, 2021 18:28
Insert appropriate code chunk in emacs buffer
(defun insert-md-code-chunk ()
"Insert Rmd code chunk"
(interactive)
(insert "```\n\n```")
(backward-char 4))
(defun insert-rmd-code-chunk ()
"Insert Rmd code chunk"
(interactive)
(insert "```{r}\n\n```")
> isIn <- function(x, y) {
+ sel <- match(x, y)
+ y[sel]
+ }
> x <- sample(LETTERS, 5)
> isIn(x, LETTERS)
[1] "Q" "Z" "K" "V" "U"
>
> x
[1] "Q" "Z" "K" "V" "U"
@lgatto
lgatto / test.Rmd
Last active August 29, 2015 14:05
Inline and external apps in Rmd
---
title: " Embedded Shiny Apps"
runtime: shiny
output:
html_document:
theme: united
---
## Setup
@lgatto
lgatto / curse-of-dimensionality.R
Created April 29, 2015 22:57
Curse of dimensionality
d <- 1:200
N <- 1000
dat <- lapply(d, function(i) replicate(i, runif(N)))
nout <- function(m) mean(apply(m, 1, function(i) any(i < 0.01 | i > 0.99)))
res <- sapply(dat, nout)
plot(res, type = "l",
xlab = "Number of dimensions",
@lgatto
lgatto / colour-picker.R
Last active November 7, 2015 13:37
A simple interface to select colours
colour_picker <- function() {
n <- length(colours())
i <- ceiling(sqrt(n))
m <- matrix(c(1:n, rep(NA, i^2 - n)),
ncol = i, nrow = i)
## plotting
image(m, col = colours(),
xaxt = "n", yaxt = "n")
k <- seq(0, 1, length.out = i)
kk <- expand.grid(k, k)
def fib(n):
fib = [0, 1]
while len(fib) < n+1:
fib.append(fib[-2] + fib[-1])
return fib[1:]
@lgatto
lgatto / keybase.md
Last active December 30, 2022 18:30

Keybase proof

I hereby claim:

  • I am lgatto on github.
  • I am lgatto (https://keybase.io/lgatto) on keybase.
  • I have a public key whose fingerprint is 3228 0F50 8589 B085 9E3D A828 0C03 2B80 46E2 E38A

To claim this, I am signing this object:

@lgatto
lgatto / emacs-test.el
Last active January 26, 2016 16:11
emacs-poly-mode-debugging
(setq package-user-dir (expand-file-name "~/fmp"))
(require 'package)
(package-initialize)
(require 'ess-site)
(require 'poly-R)
(require 'poly-markdown)
@lgatto
lgatto / hyperlopit-tfe.R
Last active February 10, 2016 10:38
Tfe3 and hyperLOPIT plot
## load packages and data
library("pRoloc")
library("pRolocdata")
data(hyperLOPIT2015)
## produce PCA plot
plot2D(hyperLOPIT2015)
addLegend(hyperLOPIT2015, where = "bottomleft", cex = .7)
## Find Tfe3's identifier and define it as a