Skip to content

Instantly share code, notes, and snippets.

View abalter's full-sized avatar

Ariel Balter abalter

  • Center For Health Systems Effectiveness, OHSU
  • Portland, OR
View GitHub Profile
@idahopotato1
idahopotato1 / index.html
Created April 9, 2021 00:02
Resize, Drag, Snap
<div id="pane">
<div id="title">Resize, Drag or Snap Me!</div>
</div>
<div id="ghostpane"></div>
@dlaehnemann
dlaehnemann / Rstudio_ubuntu_conda_r_installation.md
Last active August 25, 2023 09:39
Using Rstudio desktop with a custom R installation under Ubuntu 18.04 (in this case, conda)

I try to use conda for as many software installations in data analysis as possible, as this will ususally guarantee that I can use up to date versions of that software.

This now includes R, and as I mostly use R through Rstudio Desktop, I checked how I can use a custom R installation with Rstudio Desktop. As described in the Rstudio docs, you just have to set the environment variable RSTUDIO_WHICH_R to the R binary of your wanted installation. For this environment variable to be set when launching Rstudio from Ubuntu's application launcher, you have to make the respective environment setting in the rstudio.desktop file.

As a reminder for me, and maybe as info for others, the general setup is:

  1. Install Rstudio: https://www.rstudio.com/products/rstudio/download/#download
  2. Install (Mini-)conda: https://conda.io/miniconda.html
@elowy01
elowy01 / BCFtools cheat sheet
Last active May 15, 2024 04:33
BCFtools cheat sheet
*bcftools filter
*Filter variants per region (in this example, print out only variants mapped to chr1 and chr2)
qbcftools filter -r1,2 ALL.chip.omni_broad_sanger_combined.20140818.snps.genotypes.hg38.vcf.gz
*printing out info for only 2 samples:
bcftools view -s NA20818,NA20819 filename.vcf.gz
*printing stats only for variants passing the filter:
bcftools view -f PASS filename.vcf.gz
@crawles
crawles / bq_load_tsv.sh
Created June 13, 2018 16:40
How to load a TSV file into BigQuery
# Can work for other delimiters as well
# Tab delimiter
bq load --source_format=CSV --field_delimiter=tab \
--skip_leading_rows 1 -<destination_table> <source> \
<schema>
@apaskulin
apaskulin / advanced-formatting-github-markdown.md
Created April 15, 2018 17:49
Tips and tricks for more formatting options in GitHub Markdown

Advanced Formatting in GitHub Markdown

GitHub Flavored Markdown lets you create useful documents in GitHub and GitHub Enterprise using .md files. Like other varieties of markdown, GitHub Markdown tries to be as readable as possible in its raw form, resulting in an intentionally limited set of formatting options. However, these options can feel restrictive when dealing with complex content.

Although GitHub Markdown strips out most HTML tags, here are a few tricks that can give you more flexibility when formatting your documents. These advanced formatting options can make your documents more useable, but they come at the expense of plain text readability, so use with caution.

@Mukei
Mukei / conda_environment_rename.sh
Created November 30, 2017 07:01
How to rename a conda environment (workaround)
#One workaround is to create clone environment, and then remove original one:
#(remember about deactivating current environment with deactivate on Windows and source deactivate on macOS/Linux)
conda create --name new_name --clone old_name --offline #use --offline flag to disable the redownload of all your packages
conda remove --name old_name --all # or its alias: `conda env remove --name old_name`
#There are several drawbacks of this method:
# time consumed on copying environment's files,
# temporary double disk usage.
@simecek
simecek / rmagic_example.ipynb
Last active January 16, 2021 13:29
How to add R code to your (IPython) Jupyter Notebook
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ramhiser
ramhiser / character2factor.r
Created February 10, 2017 19:13
Convert all character columns to factors using dplyr in R
library(dplyr)
iris_char <- iris %>%
mutate(Species=as.character(Species),
char_column=sample(letters[1:5], nrow(iris), replace=TRUE))
sum(sapply(iris_char, is.character)) # 2
iris_factor <- iris_char %>%
mutate_if(sapply(iris_char, is.character), as.factor)
# Sepal.Length Sepal.Width Petal.Length Petal.Width Species char_column
# "numeric" "numeric" "numeric" "numeric" "character" "character"
@conormm
conormm / r-to-python-data-wrangling-basics.md
Last active April 24, 2024 18:22
R to Python: Data wrangling with dplyr and pandas

R to python data wrangling snippets

The dplyr package in R makes data wrangling significantly easier. The beauty of dplyr is that, by design, the options available are limited. Specifically, a set of key verbs form the core of the package. Using these verbs you can solve a wide range of data problems effectively in a shorter timeframe. Whilse transitioning to Python I have greatly missed the ease with which I can think through and solve problems using dplyr in R. The purpose of this document is to demonstrate how to execute the key dplyr verbs when manipulating data using Python (with the pandas package).

dplyr is organised around six key verbs:

@dannvix
dannvix / es6-tagged-template.js
Created July 13, 2015 14:22
Python-like template string in ECMAScript 6
// Python-like template string in ECMAScript 6 "tagged template"
// inspired from http://stackoverflow.com/a/22619256
function formatter(literals, ...substitutions) {
return {
format: function() {
let out = [], i = 0, k = 0;
for (i,k; i < literals.length; i++) {
out[k++] = literals[i];
out[k++] = Number.isInteger(substitutions[i]) ?
arguments[substitutions[i]] :