The disappearing mouse pointer…

May 31, 2008 · Posted in R bloggers · Comments Off 
While designing an fMRI experiment, I ran into the problem that the mouse pointer disappears as soon as you start typing on a mac. In itself it is actually a handy feature -- hiding the mouse pointer makes sense as long as you’re typing -- but not in this particular case.

To synchronize the behavioral data with the fMRI data, a Siemens mri-scanner sends a pulse at the start of every scan, and this pulse is picked up by your mac as a ‘^’-keypress. This makes it really easy to log the scan times, but it also hides the mouse pointer every two seconds, which is extremely annoying for your participants if they have to use the mouse. I had to find a solution for this...

When google didn’t provide an answer, I came to realize that there is no way (as far as I know - please correct me if I’m wrong) to not hide the mouse pointer in OS X when you’re typing. To solve this, I came up with the following solution. First, download pinpoint, a tiny application from macchampion that displays a graphic around your mouse pointer. Then, pay the 10$ fee which allows you to add your own graphics, and add a standard mac cursor as a graphic. Now, make sure this cursor is displayed at the exact same location as your own mouse pointer, and you fixed your problem. While the real mouse pointer still disappears on every scanner pulse, the graphic stays in place, and your participants won’t even notice that the real pointer disappeared.


02_facilitiesbk

S3 vs S4, efficiency issues

May 23, 2008 · Posted in R bloggers · Comments Off 

While developing some new simulation code with S4 system I stumbled upon some big difficulties in terms of computational efficiency. That lead me to diging into archives of Rhelp and Rdevel looking for clues. I found some interesting threads that address almost exactly the same problems that I do. Read for yourself here and here, including the follow-ups by John Chambers and others.

It is almost two years since I started to use S4 extensively for almost anything I develop in R. The transparency of the code and the ease of maintenance is so much greater in S4 than in S3. Not mentioning multiple inheritance, validity checks etc.

Things seem to have improved since 2003 as this example, based on one of the posts mentioned above gave back then:

setClass("MyClass", representation(x="numeric"))
system.time( structure(list(x=rep(1, 10^7)), class="MyS3Class") )
# [1] 1.05 0.00 1.05 NA NA
system.time( new("MyClass", x=rep(1, 10^7)) )
# [1] 3.15 0.34 11.19 NA NA

So at least 3 times slower in S4 case. Now, on my P4 3.2Ghz, with R 2.7.0 gave

setClass("MyClass", representation(x="numeric"))
system.time( structure( list(x=rep(1,10^7)), class="MyS3Class") )
#   user  system elapsed
#   0.74    0.19    0.94
system.time( new("MyClass",x=rep(1,10^7)))
#   user  system elapsed
#   0.80    0.18    1.06

which is comparable.

Nevertheless, I tried code profiling on my simulation and the output revealed that the majority of the CPU time was spent on method dispatch etc. so the difference might be still substantial. Right now my code works. Perhaps at some point I’ll port some portion to S3 and compare the results…


R2jags: A Package for Running jags from R

May 21, 2008 · Posted in R bloggers · Comments Off 
I have wrote about my experience with jags here. Martyn Plummer has updated jags recently and now jags can get as he claimed. Jags is fast and its source code is more manipulable (It's written in C++).I and Masanao wrote a package, R2jags, for running jags from R. To be sure, Martyn Plummer has wrote a package, rjags, for this purpose. But our package try to mimic the way in which R2WinBUGS

Error capture

May 6, 2008 · Posted in R bloggers · Comments Off 
In a recent post to r-sig-ecology, Mike Colvin suggested the following to capture errors within a loop:

for (i in 1:1000){
fit<-try(lm(y~x,dataset))
results<- ifelse(class(fit)=="try-error", NA, fit$coefficients)
}

How to make SVN work on R-Forge and your local driver?

May 2, 2008 · Posted in R bloggers · Comments Off 
R has a new platform-R-Forge-that enables developers and users to communicate with each other. More importantly, it is a version control platform that enables different developers to keep track on what others have been working on. So that ideally, if developer A revises some code in a package, developer B will notice the change and can avoide working on the older verison of such package.Here is

Paper on GillespieSSA now published

May 2, 2008 · Posted in R bloggers · Comments Off 

My paper on the GillespieSSA package has now been published in the latest volume of Journal of Statistical Software.

Check it out.