{{ message }}

Instantly share code, notes, and snippets.

# Benjamin nutterb

• Battelle Memorial Institute
• Kentucky
Created Mar 14, 2018
Convert between number systems. Still incomplete
View convert_base
 convert_to_decimal_single <- function(x, from = 2){ coll <- checkmate::makeAssertCollection() checkmate::assert_integerish(x, add = coll) checkmate::assert_integerish(from, len = 1, lower = 1, upper = 36
Created Feb 28, 2018
Calculate total atomic mass of a compound.
View total_atomic_mass.R
 atomic_mass <- c( H = 1.008, He = 4.0026, Li = 6.94, Be = 9.0122, B = 10.81, C = 12.011, N = 14.007, O = 15.999, F = 18.998, Ne = 20.180, Na = 22.990, Mg = 24.305, Al = 26.982, Si = 28.085, P = 30.974, S = 32.06, Cl = 35.45, Ar = 39.948, K = 39.098, Ca = 40.078, Sc = 44.956, Ti = 47.867, V = 50.942, Cr = 51.996, Mn = 54.938, Fe = 55.845, Co = 58.933, Ni = 58.693, Cu = 63.546, Zn = 65.38, Ga = 69.732, Ge = 72.630, As = 74.922, Se = 78.971, Br = 79.904, Kr = 83.798, Rb = 85.468, Sr = 87.62, Y = 88.906, Zr = 91.224,
Created Dec 5, 2017
View risk.R
 risk_attack_succeed_sim <- function(attack, defend){ while(attack >= 2 && defend > 0){ n_attack <- min(c(3, attack - 1)) n_defend <- min(c(2, defend)) roll_attack <- sample(1:6, n_attack, replace = TRUE) roll_defend <- sample(1:6, n_defend, replace = TRUE) n_compare <- min(c(n_attack, n_defend))
Created Nov 21, 2017
View numeric summary table
 quick_summary <- function(df, vars, group = NULL){ group_is_null <- is.null(group) coll <- checkmate::makeAssertCollection() checkmate::assert_data_frame(x = df, add = coll) checkmate::assert_character(x = vars,
Created Sep 12, 2017
tidy.microbenchmark
View tidy.microbenchmark
 tidy.microbenchmark <- function(x, unit, ...){ summary(x, unit = unit) }
Created Jul 12, 2017
Comparing code efficiency of multiple assertions in checkmate
View massert.R
 # Suppose we have arguments for power and sample size of a two-sample t-test # (Similar to power.t.test, but vectorized. See https://github.com/nutterb/StudyPlanning/blob/devel/R/test_t2.R # delta: Difference of means. (-Inf, Inf) # delta0: Difference under the null hypothesis. (-Inf, Inf) # se: Standard error (0, Inf) # alpha: significance level (0, 1) # power: power of the test (0, 1) ### STANDARD ARGUMENT CHECKS ### # 19 lines of code (259 characters)
Created May 30, 2017
Execute queries to SQL Server that involve VARCHAR(MAX) variable types.
View query_varchar_max
 #' @name query_varchar_max #' @title Query a VARCHAR(MAX) Variable from SQL Server #' #' @importFrom RODBCext sqlExecute #' #' @description The RODBC driver to SQL Server (SQL Server Native Client 11.0) #' reports the lenght of a VARCHAR(MAX) variable to be zero. This presents #' difficulties in extracting long text values from the database. Often, the #' ODBC will assume a length of 255 characters and truncate the text to that #' many characters. The approach taken here searches the VARCHAR(MAX) variables
Created Mar 15, 2017