Skip to content

Instantly share code, notes, and snippets.

@kevinushey
kevinushey / # llvm - 2017-07-01_09-17-42.txt
Created July 1, 2017 17:39
llvm on macOS 10.12.5 - Homebrew build logs
Homebrew build logs for llvm on macOS 10.12.5
Build date: 2017-07-01 09:17:42
@kevinushey
kevinushey / rstudio-windows-encoding-workarounds.R
Created September 23, 2016 18:24
Some workarounds for mis-encoded environment variables on Windows for users with non-ASCII characters in their username.
# Place this in a file at '~/.Rprofile' to ensure it's sourced on startup
.First <- function() {
# RStudio-specific startup
if (!is.na(Sys.getenv("RSTUDIO", unset = NA)) &&
Sys.info()[["sysname"]] == "Windows")
{
# work around mis-encoded environment variables
USERPROFILE <- Sys.getenv("USERPROFILE")
HOME <- file.path(USERPROFILE, "Documents", fsep = "\\")
R_USER <- HOME
@kevinushey
kevinushey / server.R
Created September 4, 2014 23:53
Input slider has some bugs when used through uiOutput
library(shiny)
## Example
# shinyServer(function(input, output) {
# output$value <- renderPrint({ input$sliderId })
# })
## uiOutput
shinyServer(function(input, output) {
output$slider <- renderUI({
@kevinushey
kevinushey / clobber-plot.R
Created September 4, 2014 00:33
Clobbering plot with your own S4 generic
setGeneric("plot", function(x, ...) {
standardGeneric("plot")
})
setMethod("plot", list(x = "ANY"), function(x, ...) {
UseMethod("plot")
})
@kevinushey
kevinushey / enumerate.R
Last active November 10, 2022 21:16
A python-style enumerate function for R.
enumerate <- function(X, FUN, ...) {
result <- vector("list", length(X))
for (i in seq_along(result)) {
tmp <- FUN(X[[i]], i, ...)
if (is.null(tmp))
result[i] <- list(NULL)
else
result[[i]] <- tmp
}
result
@kevinushey
kevinushey / r_mac_osx_binary_compat.R
Created August 15, 2014 22:45
Find packages that may have binary incompatibilities on Mac OS X
otool <- Sys.which("otool")
if (otool == "") {
stop("This utility requires 'otool' to run")
}
allPackages <- list.files(.libPaths(), full.names = TRUE)
stdLibsUsed <- lapply(allPackages, function(path) {
pkgName <- basename(path)
libPath <- file.path(path, "libs", paste0(pkgName, ".so"))
if (!file.exists(libPath)) {
@kevinushey
kevinushey / API.R
Last active August 29, 2015 14:02
Tracking the API of a CRAN package over time
if (!require(httr)) {
devtools::install_github("httr")
library(httr)
}
get_archived_packages <- function(package, repo, where) {
archive <- file.path(repo, "Archive", package)
response <- httr::GET(archive)
if (response$status_code == "404")
stop("Could not access page at '", archive, "'.")
@kevinushey
kevinushey / longest_arg_name.R
Created May 15, 2014 04:08
Which function has the longest argument name?
for (package in installed.packages()[, 1])
library(package, character.only = TRUE)
ns <- search()
output <- vector("list", length(ns))
for (i in seq_along(output)) {
namespace <- ns[[i]]
env <- as.environment(namespace)
objs <- mget(
objects(envir = env),
@kevinushey
kevinushey / names_copy.R
Last active August 29, 2015 13:57
When does `names<-` copy?
df <- data.frame(x=1)
x <- capture.output(.Internal(inspect(df)))
names(df) <- "a"
y <- capture.output(.Internal(inspect(df)))
internal_diff <- function(x, y) {
xp <- file.path( tempdir(), "Rdiff1.txt" )
yp <- file.path( tempdir(), "Rdiff2.txt" )
cat(x, file=xp, sep="\n")
cat(y, file=yp, sep="\n")
@kevinushey
kevinushey / position_jitterdodge.R
Last active August 29, 2015 13:57
Combine position_jitter and position_dodge so points can align with boxplots in ggplot2
#' Jitter-dodge points to align them with a boxplot including fill aesthetic
#'
#' @family position adjustments
#' @param width degree of jitter in x direction. Defaults to 40\% of the
#' resolution of the data.
#' @param height degree of jitter in y direction. Defaults to 40\% of the
#' resolution of the data
#' @export
#' @examples
#' dsub <- diamonds[ sample(1:nrow(diamonds), 1000), ]