Articles by Lee Pang

Desktop DeployR

April 13, 2016 | Lee Pang

I'm going to be giving a talk this Thursday at my local R/Data Science Meetupabout my method for deploying self contained desktop R applications. Since my original post on the subject (over 2 years ago!) I've made manyof improvements thanks to the many useful comments I received and my own "... [Read more...]

Desktop DeployR

April 13, 2016 | Lee Pang

I'm going to be giving a talk this Thursday at my local R/Data Science Meetupabout my method for deploying self contained desktop R applications. Since my original post on the subject (over 2 years ago!) I've made manyof improvements thanks to the many useful comments I received and my own "... [Read more...]

Paging Widget for Shiny Apps

October 21, 2015 | Lee Pang

In my last post I described how I built a shiny application called “DFaceR” that used Chernoff Faces to plot multidimensional data. To improve application response time during plotting, I needed to split large datasets into more manageable “pages” to be plotted. Rather than take the path of least resistance ... [Read more...]

Paging Widget for Shiny Apps

October 21, 2015 | Lee Pang

In my last post I described how I built a shiny application called “DFaceR” that used Chernoff Faces to plot multidimensional data. To improve application response time during plotting, I needed to split large datasets into more manageable “pag... [Read more...]

Facing your data

October 10, 2015 | Lee Pang

A few years ago, I came across a post on FlowingData about using Chernoff Faces as a fun way to visualize multidimensional data:
<span>></span><span> </span><span>The</span><span> assumption </span><span>is</span><span> that we can read people</span><span>'s faces easily in real life, <br>> so we should be able to recognize small differences when they represent data. <br>> Now that'</span><span>s a pretty big assumption</span><span>,</span><span> but debate aside</span><span>,</span><span> they</span><span>'re fun to make.</span>
I showed this concept to a coworker, who found it amusing and championed (albeit in jest) making an application to enable scientists at our company to ... [Read more...]

Facing your data

October 10, 2015 | Lee Pang

A few years ago, I came across a post on FlowingData about using Chernoff Faces as a fun way to visualize multidimensional data: __ The assumption is that we can read people's faces easily in real life, __ so we should be able to recognize small di... [Read more...]

Easy error propagation in R

January 22, 2015 | Lee Pang

In a previous post I demonstrated how to use R’s simple built-in symbolic engine to generate Jacobian and (pseudo)-Hessian matrices that make non-linear optimization perform much more efficiently. Another related application is Gaussian error propagation. Say you have data from a set of measurements in variables x and ... [Read more...]

R OOP – a little privacy please?

August 23, 2014 | Lee Pang

As of late, I’ve been making heavy use of Reference Classes in R. They are easier for me to wrap my mind around since they adopt a usage style more like “traditional” OOP languages like Java. Primarily, object methods are part of the class definition and accessed via the ... [Read more...]

Optimizing with R expressions

August 21, 2014 | Lee Pang

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.... [Read more...]

Deploying Desktop Apps with R

April 2, 2014 | Lee Pang

(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 ... [Read more...]

An R flaw: unexpected attribute droppings

February 6, 2014 | Lee Pang

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:
<span>></span><span> aa </span><span>=</span><span> array</span><span>(</span><span>runif</span><span>(</span><span>2</span><span>*</span><span>3</span><span>*</span><span>4</span><span>),</span><span> <br>             dim</span><span>=</span><span>c</span><span>(</span><span>2</span><span>,</span><span>3</span><span>,</span><span>4</span><span>),</span><span> <br>             dimnames</span><span>=</span><span>list</span><span>(</span><span>id  </span><span>=</span><span> c</span><span>(</span><span>good</span><span>=</span><span>'id1'</span><span>,</span><span> evil</span><span>=</span><span>'id2'</span><span>),</span><span> <br>                           x   </span><span>=</span><span> c</span><span>(</span><span>1</span><span>,</span><span>2</span><span>,</span><span>3</span><span>),</span><span> <br></span><span>var</span><span> </span><span>=</span><span> c</span><span>(</span><span>up</span><span>=</span><span>'a'</span><span>,</span><span> dn</span><span>=</span><span>'b'</span><span>,</span><span> lt</span><span>=</span><span>'c'</span><span>,</span><span> rt</span><span>=</span><span>'d'</span><span>)))</span><span><br></span><span>></span><span> str</span><span>(</span><span>aa</span><span>)</span><span><br> num </span><span>[</span><span>1</span><span>:</span><span>2</span><span>,</span><span> </span><span>1</span><span>:</span><span>3</span><span>,</span><span> </span><span>1</span><span>:</span><span>4</span><span>]</span><span> </span><span>0.0138</span><span> </span><span>0.2942</span><span> </span><span>0.7988</span><span> </span><span>0.3465</span><span> </span><span>0.8751</span><span> </span><span>...</span><span><br></span><span>-</span><span> attr</span><span>(*,</span><span> </span><span>"dimnames"</span><span>)=</span><span>List</span><span> of </span><span>3</span><span><br></span><span>..</span><span>$ id </span><span>:</span><span> </span><span>Named</span><span> chr </span><span>[</span><span>1</span><span>:</span><span>2</span><span>]</span><span> </span><span>"id1"</span><span> </span><span>"id2"</span><span><br></span><span>..</span><span> </span><span>..-</span><span> attr</span><span>(*,</span><span> </span><span>"names"</span><span>)=</span><span> chr </span><span>[</span><span>1</span><span>:</span><span>2</span><span>]</span><span> </span><span>"good"</span><span> </span><span>"evil"</span><span><br></span><span>..</span><span>$ x  </span><span>:</span><span> chr </span><span>[</span><span>1</span><span>:</span><span>3</span><span>]</span><span> </span><span>"1"</span><span> </span><span>"2"</span><span> </span><span>"3"</span><span><br></span><span>..</span><span>$ </span><span>var</span><span>:</span><span> </span><span>Named</span><span> chr </span><span>[</span><span>1</span><span>:</span><span>4</span><span>]</span><span> </span><span>"a"</span><span> </span><span>"b"</span><span> </span><span>"c"</span><span> </span><span>"d"</span><span><br></span><span>..</span><span> </span><span>..-</span><span> attr</span><span>(*,</span><span> </span><span>"names"</span><span>)=</span><span> chr </span><span>[</span><span>1</span><span>:</span><span>4</span><span>]</span><span> </span><span>"up"</span><span> </span><span>"dn"</span><span> </span><span>"lt"</span><span> </span><span>"rt"</span>
Thus, I could access “aliases” for dimension names in id and var by:
<span>></span><span> names</span><span>(</span><span>dimnames</span><span>(</span><span>aa</span><span>)</span><span>$id</span><span>)</span><span><br></span><span>[</span><span>1</span><span>]</span><span> </span><span>"good"</span><span> </span><span>"evil"</span><span><br></span><span>></span><span> names</span><span>(</span><span>dimnames</span><span>(</span><span>aa</span><span>)</span><span>$var</span><span>)</span><span><br></span><span>[</span><span>1</span><span>]</span><span> </span><span>"up"</span><span> </span><span>"dn"</span><span> </span><span>"lt"</span><span> </span><span>"rt"</span>
The code ... [Read more...]

character handling: mean() vs sd()

October 21, 2013 | Lee Pang

Here’s a weird R error/bug/nuance I came across today: What would you expect the following lines of code to return?
<span>x </span><span>=</span><span> c</span><span>(</span><span>'1'</span><span>,</span><span> </span><span>'2'</span><span>,</span><span> </span><span>'3'</span><span>)</span><span><br>mean</span><span>(</span><span>x</span><span>)</span><span><br>sd</span><span>(</span><span>x</span><span>)</span>
Well, apparently it is:
<span># mean(x)</span><span><br></span><span>[</span><span>1</span><span>]</span><span> NA<br><br></span><span># sd(x)</span><span><br></span><span>[</span><span>1</span><span>]</span><span> </span><span>1</span>
So, sd() silently converts its input to numeric, while mean() does not. More evidence of this is in the source:
<span>></span><span> mean<br></span><span>function</span><span> </span><span>(</span><span>x</span><span>,</span><span> </span><span>...)</span><span> <br></span><span>UseMethod</span><span>(</span><span>"mean"</span><span>)</span><span><br></span><span><</span><span>bytecode</span><span>:</span><span> </span><span>0x000000001165e790</span><span>></span><span><br></span><span><</span><span>environment</span><span>:</span><span> </span><span>namespace</span><span>:</span><span>base</span><span>></span><span><br><br></span><span>></span><span> sd<br></span><span>function</span><span> </span><span>(</span><span>x</span><span>,</span><span> na</span><span>.</span><span>rm </span><span>=</span><span> FALSE</span><span>)</span><span> <br>sqrt</span><span>(</span><span>var</span><span>(</span><span>if</span><span> </span><span>(</span><span>is</span><span>.</span><span>vector</span><span>(</span><span>x</span><span>))</span><span> x </span><span>else</span><span> </span><span>as</span><span>.</span><span>double</span><span>(</span><span>x</span><span>),</span><span> na</span><span>.</span><span>rm </span><span>=</span><span> na</span><span>.</span><span>rm</span><span>))</span><span><br></span><span><</span><span>bytecode</span><span>:</span><span> </span><span>0x000000001158eb00</span><span>></span><span><br></span><span><</span><span>environment</span><span>:</span><span> </span><span>namespace</span><span>:</span><span>stats</span><span>></span>
... [Read more...]

RegEx: Named Capture in R (Round 2)

October 9, 2013 | Lee Pang

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...]

Groan – my first R package

August 20, 2013 | Lee Pang

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 | Lee Pang

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...]

PID Control-R

February 8, 2013 | Lee Pang

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...]

Set operations on more than two sets in R

February 6, 2013 | Lee Pang

ProblemSet operations are a common place thing to do in R, and the enabling functions in the base stats package are:intersect(x, y)union(x, y)setdiff(x, y)setequal(x, y)That said, you'll note that each ONLY takes two arguments - i.e. set X and set ... [Read more...]

A copper toned publication!

January 21, 2013 | Lee Pang

At long last (1.5yrs since the first submission attempt to be exact), the research I worked on as a post-doctoral fellow has been published!Click on the image above to head over to the article for some light reading.  A lot of work went into this ... [Read more...]
1 2

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)