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
with combined 3-colbed + 4th col. id | |
```r | |
library(data.table) | |
y = data.table(chr=c("Chr1", "Chr1", "Chr1"), start=c(1, 15,1), | |
end=c(4, 18, 55), id=letters[1:3]) | |
setkey(y, chr, start, end) | |
dt <- foverlaps(y, y, type="any") | |
``` |
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
library(httr) | |
library(dplyr) | |
url <- "https://www.github.com" | |
# all possible alpha numeric names | |
allowed_n_letters <- 1:3 # just change this to check others... | |
possible_paths <- lapply(allowed_n_letters,function(x) { | |
combn(letters, x) %>% apply(2, paste0, collapse="") | |
}) %>% unlist() |
I have a large file (too big to read in memory) and I want to generate subsets of the file. The subsets are defined by a column in the file. In other words, I split one file into n
files where n = unique values in file column
.
library(data.table)
path <- "small.tsv"
split_file(path , col_idx = 4, chunk_size = 1e7, skip = 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
# pace to secs...minute:seconds character string to seconds integer | |
pts <- function(ms = "4:45") { | |
tmp <- as.integer(unlist(strsplit(ms, ":", fixed = TRUE))) | |
tmp[1]*60 + tmp[2] | |
} | |
# seconds to total time in hour:minute:seconds | |
ttl_time <- function(s) { | |
hrs <- floor(s / 3600) | |
leftovers <- s %% 3600 |
-
use a cache environment in
aaa_cache.R
:bg_ws
for biogrid webservice.- use a function such as
bg_ws_build()
which assigns useful variables- url
- uris (service endpoints)
- access key
- parameters
-
in
zzz.R
:
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
# John Fox's numbers2words found here: | |
# http://tolstoy.newcastle.edu.au/R/help/05/04/2715.html | |
numbers2words <- function(x){ | |
# helper | |
helper <- function(x){ | |
digits <- rev(strsplit(as.character(x), "")[[1]]) | |
nDigits <- length(digits) | |
if (nDigits == 1) as.vector(ones[digits]) | |
else if (nDigits == 2) |
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
#' the name of the package we want to check | |
pkg <- "tidyr" | |
library(pkg, character.only = TRUE) | |
#' do the work | |
pacman::p_load(readr, dplyr, tidyr, ggplot2) | |
`%||%` <- function(a, b) if (!is.null(a)) a else b | |
ui <- getNamespaceExports(pkg) | |
only_funs <- unlist(lapply(ui, function(x) is.function(get(x)))) | |
ui <- ui[only_funs] | |
l <- lapply(ui, function(f) { |
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
pacman::p_load(readr, dplyr, tidyr, ggplot2) | |
library(partitions) | |
n <- 5 | |
vals <- as.vector(parts(n)) | |
len <- length(vals) / n | |
part <- rep(1:len, each = n) | |
d <- data_frame(vals, part) | |
d <- d %>% | |
group_by(part) %>% |
OlderNewer