R6/S3 and S4: getting the best of both worlds

Why would you even want to mix these two paradigms?

I really love the design, simplicity and features of R6 classes. However, I also really like S4‘s method dispatching mechanism a lot: you can dispatch based on not just one, but multiple signature arguments.

Thus, sometimes you just want it all: use R6 instead of S4 classes, but they should also play nicely with/in S4 methods.

What do you need to do?

When you want to use instances of R6 classes as signature arguments of S4 methods, you need to create “formal S4 equivalents” for your R6 classes. Furthermore, you need to make sure that the S3 inheritance structure is correctly represented as well.

Let’s start out with some R6 class definitions:

require("R6")
ClassA <- R6Class("ClassA",
public = list(foo = function() "foo!"))
ClassB <- R6Class("ClassB", inherit = ClassA,
public = list(bar = function() "bar!"))

Continue reading “R6/S3 and S4: getting the best of both worlds”

Color Theme for Eclipse IDE + StatET Editor: rappster

I’ve played around a bit with the Eclipse Color Themes plugin by Felix Dahlke and Roger Dudler as they added support for the R editor that ships with plugin StatET late last year.

The outcome is a little color theme called rappster. The nice thing with those color themes is that you can make your syntax highlighting settings portable as you can simply import the theme of your choice in another instance of Eclipse, e.g. when updating to a newer version.

Continue reading “Color Theme for Eclipse IDE + StatET Editor: rappster”

Update your Windows PATH – revisited

Yihui got me psyched a little about GitHub 😉

After my last post about running your R infrastructure from an USB drive, he commented on my function that would update the Windows PATH (which is at least important for R and Rtools).

Now I found some time to polish it a little. Feel free to test (there’s a little example script) and comment on it on GitHub!

UPDATE 2012-03-07

Some further tweaking:

Note: you do need to other functions/methods in R

Greetz

RMySQL: using the latest MySQL version

In order to connect my R related stuff to a webserver and MySQL I went all the way from using xampp to setting up my own (W)AMPP  (Apache MySQL PHP Perl) to finally back to using xampp. And I’m quite happy about this very last switch to xampp!

Why I like xampp

  • it’s open-source and actively maintained (thanks to the guys over at ApacheFriends.org!)
  • it can be run as a portable app from an USB device
  • it’s hassle free when you want to use an AMPP bundle but don’t like to spend your time configuring the whole thing

Continue reading “RMySQL: using the latest MySQL version”

Running your R and LaTeX Infrastructure from a portable USB Drive

On my road to eventually running all of my programs off an USB device I’ve gotten a little bit closer yesterday thanks to input from Duncan Murdoch and Yihui Xie.

Eventually running the entire Windows OS off a USB drive would be nice (not talking about running it as a Virtual Machine, but to have a bootable Windows on USB), so: any hints appreciated 😉

My current R devel infrastructure consists of

Continue reading “Running your R and LaTeX Infrastructure from a portable USB Drive”

Indexing Nested Lists

I’ve long searched for a somewhat efficient approach to indexing nested lists and/or environments and here’s my best solution so far.

For me, being able to compute such an index is the crucial part in order to actually manage such nested structures (which are very helpful in a lot of scenarios where formal classes are too inflexible). What you need to master are a) being able to select a specific branch in the nested list and b) being able to update it (e.g. adding new branches). A use case would be parsing a config file format to a nested list structure.

Continue reading “Indexing Nested Lists”

Doing away with “unknown timezone” warnings

Timezone stuff can really drive you NUTS

– at least if you’re sitting in front of a German Windows-Box 😉

This is what I used to do to set my tz:


options(tz="Europe/Berlin")

And I always wondered why R would throw “unknown timezone” warnings:


> t <- "2011-11-08 09:42:00"
 > as.POSIXct(t, tz=getOption("tz"))
 [1] "2011-11-08 09:42:00 CET"
 Warning messages:
 1: In strptime(xx, f <- "%Y-%m-%d %H:%M:%OS", tz = tz) :
 unknown timezone 'MET-1MST'
 2: In as.POSIXct.POSIXlt(x) : unknown timezone 'MET-1MST'
 3: In strptime(x, f, tz = tz) : unknown timezone 'MET-1MST'
 4: In as.POSIXct.POSIXlt(as.POSIXlt(x, tz, ...), tz, ...) :
 unknown timezone 'MET-1MST'
 5: In as.POSIXlt.POSIXct(x, tz) : unknown timezone 'MET-1MST'

Someday I found out that setting tz via `options()` was not enough as the environment variable `TZ` is not affected and hence all the the trouble:


> Sys.getenv("TZ")
 [1] "MET-1MST"

Changing this should do away with the nasty warnings:


> Sys.setenv(TZ="Europe/Berlin")
 > Sys.getenv("TZ")
 [1] "Europe/Berlin"
 > as.POSIXct(t, tz=getOption("tz"))
 [1] "2011-11-08 09:42:00 CET"

Identifying Records in Data Frame A That Are Not Contained In Data Frame B – A Comparison

Yesterday I launched my first question at Stackoverflow and apparently did a lot of things wrong as I managed to get my question closed wihtin hours 😉

http://stackoverflow.com/questions/7728462/identify-records-in-data-frame-a-not-contained-in-data-frame-b

I had collected 9 different solutions to the problem and made the mistake to put it all within the original question space. So people complained and told me that such a collection belongs into a blog and not on Stackoverflow. Hence, I decided to go ahead and finally make my first blogging steps! I’ll probably still miss out on a lot of cool technical stuff on the blog, so please bear with me.

Continue reading “Identifying Records in Data Frame A That Are Not Contained In Data Frame B – A Comparison”