Skip to content

Instantly share code, notes, and snippets.

@nathania
nathania / installation.md
Created February 14, 2023 18:32 — forked from juliasilge/installation.md
Installing R + Tensorflow on M1
@nathania
nathania / move_slides_to_web.R
Created March 31, 2019 13:14 — forked from malcolmbarrett/move_slides_to_web.R
Move R Markdown HTML slides to Blogdown and Push to Web
# install.packages(c("here", "fs", "stringr", "purrr", "git2r"))
# to add invisibly in your R profile, open with usethis::edit_r_profile()
# then define it in an environment, e.g.
# .env <- new.env()
# .env$move_slides_to_web <- {function definition}
move_slides_to_web <- function(folder = NULL, index = NULL) {
if (is.null(folder)) {
@nathania
nathania / RStudio Community reply 2019-03-13
Last active March 14, 2019 02:32
RStudio Community reply: How to apply a plotting function to a list of dataframes *and* a character vector
# https://community.rstudio.com/t/how-to-apply-a-plotting-function-to-a-list-of-dataframes-and-a-character-vector/26033
library(tidyverse)
library(scales)
library(naniar)
# original viz ------------------------------------------------------------
cols <- c('Good' = '#1a9641',
@nathania
nathania / ruler.R
Created March 12, 2019 20:31 — forked from hadley/ruler.R
ruler <- function(width = getOption("width")) {
x <- seq_len(width)
y <- dplyr::case_when(
x %% 10 == 0 ~ as.character((x %/% 10) %% 10),
x %% 5 == 0 ~ "+",
TRUE ~ "-"
)
cat(y, "\n", sep = "")
cat(x %% 10, "\n", sep = "")
}
@nathania
nathania / RStudio_rawdatalistr_untitled_C4A976C6
Last active March 12, 2019 19:58
generate all 2^(dim(S)) combinations of elements from a set S
# `expand(df, nesting(patient, PCP), event_type)`
# generates all unique combinations in `(patient, PCP) x event_type`.
# That is; there will be `n_distinct(df$event_type)` rows per `patient, PCP`
# tuple in the data
#
# df <- tibble(x = 1:4, y = letters[1:4])
# testthat::expect_equivalent(expand(df, nesting(x, y)), distinct(df, x, y))
# testthat::expect_equivalent(expand(df, crossing(x, y)), expand(df, x, y))
# generate all combinations of elements in a set S
@nathania
nathania / rotate-axis-labels-ggplot2.R
Created December 9, 2018 01:01 — forked from benmarwick/rotate-axis-labels-ggplot2.R
I can never remember how to rotate the x-axis labels with ggplot2: theme(axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5))
# Adapted from https://stackoverflow.com/a/7267364/1036500 by Andrie de Vries
library(ggplot2)
td <- expand.grid(
hjust=c(0, 0.5, 1),
vjust=c(0, 0.5, 1),
angle=c(0, 45, 90),
text="text"
)
@nathania
nathania / pub_med.py
Created March 16, 2017 19:41 — forked from ehazlett/pub_med.py
Search PubMed with BioPython
#!/usr/bin/env python
# numpy and biopython are required -- pip install numpy biopython
from Bio import Entrez
from Bio import Medline
MAX_COUNT = 10
TERM = 'Tuberculosis'
print('Getting {0} publications containing {1}...'.format(MAX_COUNT, TERM))
@nathania
nathania / SassMeister-input-HTML.html
Created October 13, 2015 15:04
Generated by SassMeister.com.
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">
<div class="rating">
<span><i class="fa fa-male"></i></span>
<span><i class="fa fa-male"></i></span>
<span><i class="fa fa-male"></i></span>
<span><i class="fa fa-male"></i></span>
<span><i class="fa fa-male"></i></span>
</div>
#!/usr/bin/env ruby -wKU
# Adapted from Brett Terpstra’s original “Markdown to Evernote” service (http://brettterpstra.com/a-better-os-x-system-service-for-evernote-notes-with-multimarkdown/)
# Martin Kopischke 2011 – License: Creative Commons Attribution Share-Alike (CC BY-SA) 3.0 Unported (http://creativecommons.org/licenses/by-sa/3.0/)
# Changes: – create only one Evernote note per (Multi)Markdown input passed (instead of one per line)
# – do not choke on shell escape characters (use Tempfile instead of shell pipe for osascript)
# – default to MultiMarkdown 3 executable (instead of MMD 2 Perl script)
# – make smart typography processing optional (set SMARTY to 'false' to bypass processing;
# note smart typography cannot be disabled in MMD 3.0 and 3.0.1
# – handle both smart typography processing scripts (ie. SmartyPants.pl)