Blog Archives

Optimizing with R expressions

August 21, 2014
By
Optimizing with R expressions

I recently discovered a powerful use for R expression()’sSay you are trying to fit some experimental data to the following nonlinear equation: Ky0eu(x−tl)K+y0(eu∗(x−tl)−1)+b1+(b0−b1)e−kx+b2x with the independent variable x using nlminb() as the minimization optimizer.This sort of work is significantly improved (i.e. faster with better convergence) if an analytical gradient vector and a Hessian matrix for the objective function are provided....

Read more »

Deploying Desktop Apps with R

April 2, 2014
By

(Update) Despite the original publish date (Apr 1), this post was not and April Fools joke. I’ve also shortened the title a bit. As part of my job, I develop utility applications that automate workflows that apply more involved analysis algorithms. When feasible, I deploy web applications as it lowers installation requirements to simply a modern (standards...

Read more »

An R flaw: unexpected attribute droppings

February 6, 2014
By

Today I was putting some code together that made plots from slices of a 3-dimensional array object aa. A couple of the dimensions in aa had names defined by named vectors. For example: > aa = array(runif(2*3*4), dim=c(2,3,4), ...

Read more »

character handling: mean() vs sd()

October 21, 2013
By

Here’s a weird R error/bug/nuance I came across today: What would you expect the following lines of code to return? x = c('1', '2', '3')mean(x)sd(x) Well, apparently it is: # mean(x) NA# sd(x) 1 So, sd() silently converts its input to numeric, while mean() does not. More evidence of this is in the source: > meanfunction (x, ...)...

Read more »

RegEx: Named Capture in R (Round 2)

October 9, 2013
By

Previously, I came up with a solution to R's less than ideal handling of named capture in regular expressions with my re.capture() function. A little more than a year later, the problem is rearing its ugly - albeit subtly different - head again. I now...

Read more »

mfg, mfcol, mfrow, and layout() – secret friends

August 26, 2013
By

I was working on an issue (enhancement) today in my groan R-package today that required adding additional plotting elements via lines() and points() to a device that had already been partitioned by layout(). The code I wanted to use was essentially: #...

Read more »

Groan – my first R package

August 20, 2013
By
Groan – my first R package

Being one of two R experts at my current job I figured I should be familiar with package development. Frankly, I've been procrastinating on this topic since I started using R in 2007 - I was doing just fine with source() and the section of the R manua...

Read more »

A new R trick … for me at least

August 3, 2013
By

What were going to be talking about today are dynamic argument lists for functions. Specifically, how to unpack and prepare them in R using ..., list(), and do.call()Biased by Matlab and varargin Initially, I based my use of ... in R on my experience w...

Read more »

Non-Linear Curve Fitting is Nature Publication Worthy?

February 27, 2013
By
Non-Linear Curve Fitting is Nature Publication Worthy?

Someone needs to explain to me why this is a Nature publication ...Granted it is Nature Protocols which started its publication run when I was in grad school and is likely less high-impact as full blown Nature.  Seriously tough - using the So...

Read more »

PID Control-R

February 8, 2013
By
PID Control-R

On a whim, I thought it might be fun to try to implement a PID control algorithm ... in R.Yes, I know I have a strange idea of fun.BackgroundPID control is a heuristic method of automatically controlling processes as wide ranging as water levels in tan...

Read more »