Skip to content

Instantly share code, notes, and snippets.

@artemklevtsov
artemklevtsov / .gitlab-ci.yml
Last active January 12, 2024 04:14
Testing R package with GitLab CI (with code coverage)
variables:
CODECOV_TOKEN: "CODECOV_TOKEN_STRING"
_R_CHECK_CRAN_INCOMING_: "false"
_R_CHECK_FORCE_SUGGESTS_: "true"
APT_PKGS: "libcurl4-openssl-dev libssh2-1-dev libssl-dev libxml2-dev zlib1g-dev git"
before_script:
- apt-get update
- apt-get install -y --no-install-recommends ${APT_PKGS}
- apt-get install -y --no-install-recommends qpdf pandoc pandoc-citeproc
@magnusnissel
magnusnissel / dataframe_as_image.R
Last active August 10, 2016 13:46
A small helper function around webshot and knitr::kable to save the HTML representation of a dataframe as an image file (.png)
#This function depends on the knitr and webshot packages, uncomment lines 2-6 below if you need to install them first
#install.packages("knitr")
#install.packages("devtools")
#library(devtools)
#devtools::install_github("wch/webshot")
#webshot::install_phantomjs()
#Feel free to move the library() calls for knitr and webshot outside the function.
@expersso
expersso / trigonometry.R
Created July 28, 2016 08:44
Trigonometry with magick, gganimate, and purrr
## Purpose: illustrate use of magick, gganimate, and purrr
## Inspiration:
## https://rud.is/b/2016/07/27/u-s-drought-animations-with-the-witchs-brew-purrr-broom-magick/
## and subsequent discussion on magick vs gganimate:
## https://twitter.com/hrbrmstr/status/758304420224466944
library(purrr)
library(ggplot2)
library(gganimate)
library(animation)
library(magick)
@tuttinator
tuttinator / packages.R
Created June 28, 2016 23:25
Install packages on demand
required_packages <- c(
"dplyr",
"readr",
"ggplot2",
"ggthemes",
"futile.logger",
"lubridate"
)
packages_to_install <- required_packages[!(required_packages %in% installed.packages()[, 1])]
@aschleg
aschleg / games_howell.R
Last active November 29, 2017 00:07
R function for performing Games-Howell Post-Hoc Test
games.howell <- function(grp, obs) {
#Create combinations
combs <- combn(unique(grp), 2)
# Statistics that will be used throughout the calculations:
# n = sample size of each group
# groups = number of groups in data
# Mean = means of each group sample
# std = variance of each group sample
@benmarwick
benmarwick / potting_custom_geom_shapes.r
Last active April 27, 2021 22:05
Adjust the shape of each data point to a custom polygon using variables
#' Polygon vertices for plotting computed from an object's linear dimensions
#'
#' This function takes a data frame (one row per object) of object dimensions,
#' where each object is defined by five linear measurements, and computes coords
#' of polygon vertices at given x and y values (taken from the data frame)
#'
#' @param data data frame with at least seven numeric columns
#' @param x column for x position of polygon centers
@dgrapov
dgrapov / SOM example.R
Last active March 11, 2023 11:21
Self-organizing map (SOM) example in R
#SOM example using wines data set
library(kohonen)
data(wines)
set.seed(7)
#create SOM grid
sommap <- som(scale(wines), grid = somgrid(2, 2, "hexagonal"))
## use hierarchical clustering to cluster the codebook vectors
groups<-3
# somewhat hackish solution to:
# https://twitter.com/EamonCaddigan/status/646759751242620928
# based mostly on copy/pasting from ggplot2 geom_violin source:
# https://github.com/hadley/ggplot2/blob/master/R/geom-violin.r
library(ggplot2)
library(dplyr)
"%||%" <- function(a, b) {
@cderv
cderv / RStudio_snippet.md
Last active October 22, 2020 17:07
my custom snippet for RStudio

To insert YAML header for Rnotebook

snippet yaml_notebook_html
	#' ---
	#' title: "${1:title}"
	#' author: "${2:author}"
	#' knit: (function(inputFile, encoding) { rmarkdown::render(inputFile, encoding = encoding, output_file = sprintf("%s_%s.html", format(Sys.Date(), "%y%m%d"), basename(tools::file_path_sans_ext(inputFile))))})
	`r paste("#' date: '\u0060r paste(\u0022", format(Sys.time(), "%d/%m/%Y")," - Dernière MAJ:\u0022, format(Sys.time(), \u0022%d/%m/%Y\u0022))\u0060'", sep = "")`
	#' output : 
	#' html_document:
@bearloga
bearloga / Interactive_Presentations.Rmd
Created December 4, 2015 19:32
This allows the presenter to write and execute R code within the presentation without going back and forth between the presentation and the R console.
---
title: "Interactive Presentations"
author: "Mikhail Popov (@bearloga)"
date: "December 4, 2015"
output: ioslides_presentation
runtime: shiny
---
## Reduce Demo