setClass('Seq', representation(data = 'character', id = 'character'),
validity = function (object) is_dna(object@data))
print_fasta = function (object) {
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
modules::import_package('rlang', attach = TRUE) | |
mutate_when = function (.data, .filter, ...) { | |
dots = dots_definitions(...)$dots | |
rows = eval_tidy(enquo(.filter), .data) | |
.data[rows, names(dots)] = | |
lapply(dots, eval_tidy, data = .data[rows, , drop = FALSE]) | |
.data | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Roll your own GitHub Gist Comments Feed in R | |
library(xml2) # github version | |
library(rvest) # github version | |
library(stringr) # for str_trim & str_replace | |
library(dplyr) # for data_frame & bind_rows | |
library(pbapply) # free progress bars for everyone! | |
library(XML) # to build the RSS feed | |
who <- "hrbrmstr" # CHANGE ME! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
accession2url <- function(x) { | |
prefix <- "ftp://ftp.sra.ebi.ac.uk/vol1/fastq" | |
dir1 <- paste0("/",substr(x,1,6)) | |
dir2 <- ifelse(nchar(x) == 9, "", | |
ifelse(nchar(x) == 10, paste0("/00",substr(x,10,10)), | |
ifelse(nchar(x) == 11, paste0("/0",substr(x,10,11)), | |
paste0("/",substr(x,10,12))))) | |
paste0(prefix,dir1,dir2,"/",x) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#' (Re-)source parts of a file | |
#' | |
#' \code{rs} loads, parses and executes parts of a file as if entered into the R | |
#' console directly (but without implicit echoing). | |
#' | |
#' @param filename character string of the filename to read from. If missing, | |
#' use the last-read filename. | |
#' @param from first line to parse. | |
#' @param to last line to parse. | |
#' @return the value of the last evaluated expression in the source file. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
author: "<a href=\"http://twitter.com/klmr\">@klmr</a>" | |
title: "Gun deaths and gun ownership in the USA" | |
date: 2015-06-19 | |
output: | |
html_document: | |
theme: readable | |
--- | |
```{r echo=FALSE} | |
library(dplyr, warn.conflicts = FALSE, quietly = TRUE) |
![screenshot][]
In the following we will be using R’s “restarts” feature to implement the state machine that drives generators in languages such as Python. Generators allow lazily generating values on demand: a consumer invokes a generator, and consumes values as they are produced. A new value is only produced once the previous one has been consumed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def fib(n: int) -> int: | |
def f(n, a, b): | |
if n == 0: return a | |
if n == 1: return b | |
return f(n - 1, b, a + b) | |
return f(n, 0, 1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "mach_gettime.h" | |
#include <mach/mach_time.h> | |
#define MT_NANO (+1.0E-9) | |
#define MT_GIGA UINT64_C(1000000000) | |
// TODO create a list of timers, | |
static double mt_timebase = 0.0; | |
static uint64_t mt_timestart = 0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encode | |
tr 'A-Za-z' 'N-ZA-Mn-za-m' <<<"The Quick Brown Fox Jumps Over The Lazy Dog" | |
# decode | |
echo "Gur Dhvpx Oebja Sbk Whzcf Bire Gur Ynml Qbt" | tr '[A-Za-z]' '[N-ZA-Mn-za-m]' |