This file contains hidden or 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
str_pad <- function(str, width = floor(0.9 * getOption("width")), side = c("left", "both", "right")) { | |
side <- match.arg(side) | |
asc <- iconv(str, "latin1", "ASCII") | |
if (any(is.na(asc) | asc != str)) | |
width <- width + nchar(str, "bytes") - nchar(str, "width") | |
switch(side, | |
left = sprintf("%*s", width, str), | |
right = sprintf("%-*s", width, str), | |
both = sprintf("%-*s", width, sprintf("%*s", floor(width / 2), str))) | |
} |
This file contains hidden or 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
rm_words <- function(string, words) { | |
stopifnot(is.character(string)) | |
stopifnot(is.character(words)) | |
splitted <- strsplit(string, " ", fixed = TRUE) | |
if (length(string) > 1) | |
res <- vapply(splitted, function(x) paste(x[!tolower(x) %in% words], collapse = " "), character(1L)) | |
else | |
res <- paste(splitted[[1L]][!tolower(splitted[[1L]]) %in% words], collapse = " ") | |
return(res) | |
} |
This file contains hidden or 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
getEnvName <- function(f) { | |
attached <- c(environmentName(.GlobalEnv), loadedNamespaces()) | |
envs <- c(.GlobalEnv, lapply(attached[-1], .getNamespace)) | |
attached[vapply(envs, function(env) exists(f, env, inherits = FALSE), logical(1))] | |
} | |
# returns only a first found result | |
getEnvName2 <- function(f) { | |
envs <- c(.GlobalEnv, lapply(loadedNamespaces(), .getNamespace)) | |
for (env in envs) { |
This file contains hidden or 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
prgoressBar <- function(value = 0, label = FALSE, color = "aqua", size = NULL, | |
striped = FALSE, active = FALSE, vertical = FALSE) { | |
stopifnot(is.numeric(value)) | |
if (value < 0 || value > 100) | |
stop("'value' should be in the range from 0 to 100", call. = FALSE) | |
if (!(color %in% shinydashboard:::validColors || color %in% shinydashboard:::validStatuses)) | |
stop("'color' should be a valid status or color.", call. = FALSE) | |
if (!is.null(size)) | |
size <- match.arg(size, c("sm", "xs", "xxs")) | |
text_value <- paste0(value, "%") |
This file contains hidden or 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
melt2 <- function(data, id.vars, measure.vars, variable.name = "variable", value.name = "value", na.rm = FALSE) { | |
varnames <- names(data) | |
n <- .row_names_info(data, 2L) | |
if (!missing(id.vars) && is.numeric(id.vars)) | |
id.vars <- varnames[id.vars] | |
if (!missing(measure.vars) && is.numeric(measure.vars)) | |
measure.vars <- varnames[measure.vars] | |
if (missing(id.vars) && missing(measure.vars)) { | |
discrete <- vapply(data, function(x) is.factor(x) || is.character(x) || is.logical(x), | |
FUN.VALUE = logical(1L), USE.NAMES = FALSE) |
This file contains hidden or 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
get_psylab_images <- function(term, output.dir = ".") { | |
stopifnot(is.character(term)) | |
if (length(term) > 1L) | |
term <- paste(term, collapse = " ") | |
get_results <- function(query) { | |
api_url <- "http://psylab.info/api.php" | |
response <- httr::GET(api_url, query = query) | |
httr::stop_for_status(response, "Send API query") | |
jsonlite::fromJSON(httr::content(response, as = "text"), flatten = TRUE) | |
} |
This file contains hidden or 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
rep.data.frame <- function(x, times) { | |
x <- lapply(x, rep.int, times = times) | |
class(x) <- "data.frame" | |
if (!is.numeric(rnames <- attr(x, "row.names"))) | |
attr(x, "row.names") <- make.unique(rep.int(rnames, times)) | |
else | |
attr(x, "row.names") <- .set_row_names(length(rnames) * times) | |
x | |
} |
This file contains hidden or 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
spiral <- function(n) { | |
stopifnot(is.numeric(n)) | |
stopifnot(n > 0) | |
offset <- c(1, n, -1, -n) | |
reps <- n - seq_len(n * 2 - 1L) %/% 2 | |
indicies <- rep(rep_len(offset, length(reps)), reps) | |
indicies <- cumsum(indicies) | |
values <- integer(length(indicies)) | |
values[indicies] <- seq_along(indicies) | |
matrix(values, n, n, byrow = TRUE) |
This file contains hidden or 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
# Options | |
options(repos = list("CRAN" = "https://cloud.r-project.org/")) | |
#options(help_type = "html") | |
options(Ncpus = 4L) | |
options(digits.secs = 3) | |
options(tab.width = 4) | |
options(max.print = 100) | |
options(scipen = 10) | |
options(show.signif.stars = FALSE) | |
#options(stringsAsFactors = FALSE) |
This file contains hidden or 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
#!/usr/bin/env python | |
import sys | |
import errno | |
from argparse import ArgumentParser | |
from os.path import isfile, expanduser | |
from urllib.request import urlopen | |
if __name__ == "__main__": | |
parser = ArgumentParser(description = "Convert Good Line IPTV playlist for the SMplayer.") |