Skip to content

Instantly share code, notes, and snippets.

@gaborcsardi
gaborcsardi / Pkgdown deploy from Travis.md
Last active Oct 27, 2020
Walkthrough: deploy a pkgdown site from Travis
View Pkgdown deploy from Travis.md

Run usethis::use_pkgdown_travis()

usethis::use_pkgdown_travis()
✔ Setting active project to '/Users/gaborcsardi/works/ps'Adding 'docs/' to '.gitignore'Set up deploy keys by running `travis::use_travis_deploy()`Insert the following code in '.travis.yml'
  before_cache: Rscript -e 'remotes::install_cran("pkgdown")'
@vankesteren
vankesteren / wine_plots.R
Last active Apr 21, 2021
Plots for a wine data visualisation
View wine_plots.R
# script that outputs a graph
library(tidyverse)
library(firatheme)
wine <- read_delim("https://archive.ics.uci.edu/ml/machine-learning-databases/wine/wine.data",
delim = ",",
col_names = c(
"Cultivar", "Alcohol", "Malic acid", "Ash", "Alcalinity of ash", "Magnesium",
"Total phenols", "Flavanoids", "Nonflavanoid phenols", "Proanthocyanins",
"Color intensity", "Hue", "OD280/OD315", "Proline"
)
@pat-s
pat-s / addins.json
Last active Mar 2, 2020
Apply RStudio Desktop Settings
View addins.json
{
"styler::style_active_file": "Ctrl+Y",
"addmins::insert_dashes": "Ctrl+8",
"xaringan::inf_mr": "Ctrl+M",
"drake::rs_addin_loadd": "Ctrl+K",
"browse::browse": "Ctrl+B"
}
@clanfear
clanfear / gist:e160ba2ddf5e90c7bc70dbd2cfb0dd94
Created Aug 15, 2019
Using sf and tidyverse to get weighted mean of neighbors for all columns
View gist:e160ba2ddf5e90c7bc70dbd2cfb0dd94
library(tidyverse)
library(sf)
st_queen <- function(a, b = a){
st_relate(a, b, pattern = "F***T****")
}
new_data <- original_data %>%
mutate(neighbors = st_queen(.)) %>%
st_drop_geometry() %>%
View recentre_sf.R
st_recenter <- st_recentre <- function(x, clon = NULL, ..., tryfix = TRUE) {
if (is.null(clon)) return(x)
if (!st_is_longlat(x)) stop("recentring not appropriate for non longlat data")
## try to fix problematic geometry
if (tryfix) {
if (all(grepl("POLYGON", st_geometry_type(x)))) x <- suppressWarnings(st_buffer(sf::st_as_sf(x), 0))
x <- st_wrap_dateline(x, options = c("WRAPDATELINE=YES", "DATELINEOFFSET=180"))
}
wbox <- st_as_sfc(st_bbox(c(xmin = -180, ymin = -90, xmax = (clon)%%360 - 180, ymax = 90), crs = st_crs(x)))
west <- suppressWarnings(st_intersection(x, wbox))
@joeroe
joeroe / tidy_rcarbon.R
Created Mar 5, 2019
Tidy wrappers for the rcarbon package
View tidy_rcarbon.R
# tidy_rcarbon.R
# Tidy wrappers for the rcarbon package
#' Calibrate radiocarbon dates with tidy syntax
#'
#' A thin wrapper of [rcarbon::calibrate()] that returns calibrated dates as a
#' single list rather than a `CalDates`` object. Useful, for example, if you want
#' to add a column of calibrated dates to an existing table with [dplyr::mutate()]
#'
#' @param cra A vector of uncalibrated radiocarbon ages.
@LiYingWang
LiYingWang / wikipedia-page-edit-proportions.R
Last active Feb 11, 2019 — forked from benmarwick/wikipedia-page-edit-proportions.R
Inspect the edit history of a bunch of wikipedia pages to measure the proportion of the page contributed by each editor
View wikipedia-page-edit-proportions.R
library(tidyverse)
the_pages <- c(
"https://en.wikipedia.org/wiki/Angela_McGowan",
"https://en.wikipedia.org/wiki/Caroline_Bird_(archaeologist)",
"https://en.wikipedia.org/wiki/Jo_McDonald",
"https://en.wikipedia.org/wiki/Laurajane_Smith",
"https://en.wikipedia.org/wiki/Louise_Zarmati",
"https://en.wikipedia.org/wiki/Marcia-Anne_Dobres",
"https://en.wikipedia.org/wiki/Sarah_Colley",
@iandanforth
iandanforth / rlreproducibilitychecklist.md
Last active May 11, 2019
RL Reproducibility Checklist
View rlreproducibilitychecklist.md

A Checklist for Reproducibility in Reinforcement Learning

From a slide in a NeurIPS 2018 keynote by Joelle Pineau

For all algorithms presented, check if you include:

  • A clear description of the algorithm.
  • An analysis of the complexity (time, space, sample size) of the algorithm.
  • A link to downloadable source code, including all dependencies.
@z3tt
z3tt / data.R
Last active Aug 28, 2018
Raincloudplots - movement model versus number of infection
View data.R
dat <- structure(list(Move = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
View uc_salaries_by_dept_and_rank.R
library(XML)
library(ggplot2)
df <- readHTMLTable("http://projects.dailycal.org/paychecker/departments/")[[1]]
DeMoney <- function(x) as.numeric(gsub(",", "", gsub("\\$", "", as.character(x))))
money.columns <- c("All", "Professor", "Associate professor", "Assistant professor",
"Lecturer")