20 percent of the code has 80 percent of the errors - Lowell Arthur
Beware of bugs in the above code; I have only proved it correct, not tried it - Donald Knuth
traceback()
options(error = NULL)
load("testdump.rda")
# debugger(testdump)
debug(h)
t1 <- proc.time()
some.code()
t2 <- proc.time()
t2 - t1
pryr::address()
data.table
or tibble
instead of data.frame
Variable name | Validity |
---|---|
var1 | OK |
3way_handshake | OK |
.password | OK, hidden |
_test_ | OK |
my-matrix-M | Not good |
three.dimensional.array | OK |
3D.distance | OK |
.2objects | Not good |
wz3gei92 | Not good |
next | Not good, already existing function |
P | OK |
Q | OK |
R | OK |
S | OK |
T | Not good, TRUE or 1 |
X | Not good |
is.larger | Not good |
Raw:
myIterAtoR.max <- 5
second_iterator.max<-7
col.NUM= 10
row.cnt =10
fwzy45 <- matrix(rep(1, col.NUM*row.cnt),nrow=row.cnt)
for(haystack in (2-1):col.NUM){
for(needle in 1:row.cnt) {
if(haystack>=myIterAtoR.max){
fwzy45[haystack, needle]<-NA}
}}
Formatted
iter_max <- 5
col_num <- 10
row_num <- 10
A <- matrix(rep(1, col_num * row_num), nrow = row_num)
for (i in 1:col_num) {
for (j in 1:row_num) {
if (i >= iter_max) {
A[i, j] <- NA
}
}
}
Raw:
simulate_genotype <- function( q, N=100 ) {
if( length(q)==1 ){
p <- (1 - q)
f_gt <- c(p^2, 2*p*q, q^2) # AA, AB, BB
}else{
f_gt<-q
}
tmp <- sample( c('AA','AB','BB'), size =N, prob=f_gt, replace=T )
return(tmp)
}
Formatted:
simulate_genotype <- function(q, N = 100) {
if (length(q) == 1) {
p <- (1 - q)
f_gt <- c(p^2, 2*p*q, q^2) # AA, AB, BB
} else {
f_gt <- q
}
tmp <- sample(c('AA','AB','BB'),
size = N,
prob = f_gt,
replace = T)
return(tmp)
}
Raw:
my_filter <- function(threshold = 1, data, scalar = 5) {
data[data >= threshold] <- NA
data <- data * scalar
return(data)
}
Formatted:
my_filter <- function(data, threshold = 1, scalar = 5) {
data[data >= threshold] <- NA
data <- data * scalar
return(data)
}
Raw:
simulate_phenotype <- function(pop_params, gp_map, gtype) {
pop_mean <- pop_params[1]
pop_var <- pop_params[2]
pheno <- rnorm(n = N, mean = pop_mean, sd = sqrt(pop_var))
effect <- rep(0, times = length(N))
for (gt_iter in c('AA', 'AB', 'BB')) {
effect[gtype == gt_iter] <- rnorm(n = sum(gtype == gt_iter),
mean = gp_map[gt_iter, 'mean_eff'],
sd = sqrt(gp_map[gt_iter, 'var_eff']))
}
dat <- data.frame(gt = gtype, raw_pheno = pheno, effect = effect, pheno = pheno + effect)
return(dat)
}
Formatted: No major changes necessary
num_vec <- rep(1:10, each = 1)
calc_var <- function(vector) {
mean_val <- sum(vector)/length(vector)
sq_num <- NULL
for(i in vector) {
x <- (i - mean_val)^2
sq_num <- append(sq_num, values = x)
}
variance <- sqrt(sum(sq_num)/length(vector)-1)
return(variance)
}
variance <- calc_var(num_vec)
sd <- (variance)^2
variance
## [1] 2.692582
sd
## [1] 7.25