Skip to content

Instantly share code, notes, and snippets.

@AliciaSchep
AliciaSchep / plotly_r_update_trace_and_axis.R
Last active Jan 7, 2022
Use dropdown in R plotly to update both trace and axis title
View plotly_r_update_trace_and_axis.R
## Makes plot of either mpg or hp versus wt using mtcars dataset
## Dropdown enables toggling between what variable to plot on y axis
library(plotly)
plot_ly(mtcars, x = ~wt) %>%
add_markers(y = ~mpg, name = "mpg") %>%
add_markers(y = ~hp, name = "hp", visible = FALSE) %>%
layout(
title = "Drop down menus - Update",
xaxis = list(domain = c(0.1, 1)),
@AliciaSchep
AliciaSchep / complex_layout.json
Created Nov 19, 2017
vegalite hconcat plus vconcat plus layer
View complex_layout.json
{
"$schema": "https://vega.github.io/schema/vega-lite/v2.json",
"description": "Two horizonally concatenated charts that show a histogram of precipitation in Seattle and the relationship between min and max temperature.",
"data": {
"url": "data/weather.csv",
"format": {
"type": "csv"
}
},
"transform": [
@AliciaSchep
AliciaSchep / get_footprint.R
Created Nov 30, 2017
Compute aggregate footprint around position
View get_footprint.R
library(GenomicRanges)
library(S4Vectors)
# Footprint does not include +/- 4 correction for ATAC-seq
# Modified tabulate funcion ----------------------------------------------------
tabulate2 <- function(x, min_val, max_val) {
if (max_val <= min_val) {
stop("max_val must be greater than min_val")
View simpelist_coercion_example.r
setClass("DummyClass",
slots = c(y = "numeric"))
setClass("SpecialClass",
slots = c(x = "numeric"),
contains = c("DummyClass"))
setClass("SpecialList",
@AliciaSchep
AliciaSchep / fresh_r_libraries.r
Created Feb 19, 2018
Setup use of a new, fresh library directory in R
View fresh_r_libraries.r
create_lib_dir <- function(name, path = "."){
dir_path <- file.path(path, name)
if (!dir.exists(dir_path)) {
message("Creating new dir: ", dir_path)
dir.create(dir_path)
}
normalizePath(dir_path)
}
@AliciaSchep
AliciaSchep / get_libs_used.r
Created Feb 19, 2018
Find the r packages used in directory
View get_libs_used.r
get_r_files <- function(path = ".", recursive = FALSE, include_rmd = TRUE){
all_files <- normalizePath(list.files(path, full.names = TRUE,
recursive = recursive))
r_files <- grep(".*\\.(r|R)$", all_files, value = TRUE)
if (include_rmd){
r_files <- c(r_files,
grep(".*\\.(r|R)md$", all_files, value = TRUE))
}
@AliciaSchep
AliciaSchep / event_listener_bug_example.Rmd
Created Apr 12, 2018
Example document showcasing a bug with inappropriate insertion of wheel event listener by rstudio in rmarkdown inline view / notebook
View event_listener_bug_example.Rmd
---
title: "event listener bug"
author: "Alicia Schep"
date: "April 11, 2018"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
@AliciaSchep
AliciaSchep / deploy_to_gh_pages.r
Last active Mar 9, 2019
Deploy a pkgdown site to gh_pages branch
View deploy_to_gh_pages.r
## Adapted from r-lib/pkgdown source code from RStudio https://github.com/r-lib/pkgdown
## Helper functions, directly from pkgdown code --------------------------------
git <- function(...) {
processx::run("git", c(...), echo_cmd = TRUE, echo = TRUE)
}
github_clone <- function(dir, repo_slug) {
remote_url <- sprintf("git@github.com:%s.git", repo_slug)
cli::rule("Cloning existing site", line = 1)
View plotly_dropdown_example.R
p <- plot_ly(mtcars, x = ~wt) %>%
add_markers(y = ~mpg, name = "A") %>%
add_markers(y = ~hp, name = "B", visible = F) %>%
layout(
title = "Drop down menus - Update",
xaxis = list(domain = c(0.1, 1)),
yaxis = list(title = "mpg"),
updatemenus = list(
list(
y = 0.7,
@AliciaSchep
AliciaSchep / cute_email_gadget.R
Created Apr 14, 2019
Shiny Gadget For Emailing Cute Puppies
View cute_email_gadget.R
library(shiny)
library(miniUI)
library(gmailr)
library(rtweet)
library(purrr)
use_secret_file("~/client_id.json")
send_email <- function(to_address, picture_url, msg = "",
subject = "Cute Picture", expanded_url = picture_url){