Raspberry Pi And R


[Stephen] picked up a Raspberry Pi to do a little hardware hacking and add a blinking LED to the many feathers in his software development hat. He picked up an analog to digital converter and a temperature sensor that would serve him well in a few projects he wanted to put together, including a weather station and a small Pi-controlled home brewing setup. He ended up not liking Python, and didn’t like the C-ness of wiringPi. He’s a scientist, so he’s most comfortable with R and Matlab. Of course, playing around with a R and a Raspberry Pi means replicating his sensor-reading code in R.

[Stephen] put together a neat little package that will allow him to read his sensors over an SPI bus with his Raspberry Pi. Yes, this functionality can easily be duplicated with Python, but if you’re looking to generate beautiful graphs, or just do a whole lot of statistics on something, R is the tool you need.

It’s a cool project, even if it is only measuring the temperature. Using R for the nerd cred isn’t bad, either.

10 thoughts on “Raspberry Pi And R

  1. Actually pythons matplotlib is damn slow when you are looking for >10fps. Otoh this project will most probably not be about fast plotting.

    I’d be interested what he disliked about python _and_ C … last time I checked out R it was very C-like. With some operators inspired by math for good measure.

    1. So you perhaps saw my reply to the comment below, however I’ll clarify on the C and Python thing. If you read my original Google+ post, I only said I disliked Python (for some reason I’ve always found the look and feel of Python kind of icky when I’ve played around with the code).

      Concerning C, in truth I’ve never programmed in it, so I don’t like or dislike it. In fact, I had originally intended on trying to do a full C implementation of the sensor reading+COSM function to try to make it very fast as compared to the Adafruit python example and also as a first project to get me more familiar with C. However I was at a loss to how I would send data to COSM this way, and thus only used C in this project as an interface with libwiringPi. I ripped out the readadc function from the Raspberry Pi hobbyist blog linked in my G+ post, and compiled it into a small library linked with R (which is then loaded into memory in my R script), and use it to talk to the A to D with R’s .C function.

  2. Haven’t seen it implemented on a Raspberry Pi yet, but I think you can make better looking charts with matplotlib than with R. There are also some excellent stats libraries.

    Not saying there aren’t legitimate reasons to use R and Matlab (the most important being familiarity), but I think python is also a good choice.

    1. So I’m the Stephen who wrote the R sensor code referred to in this post.

      My reasons for using R go back about ten years ago while working on my dissertation. I experimented extensively with several different integrated plotting and data analysis packages, including matplotlib, Matlab, Octave, R, SPSS, and SAS. I decided I liked R the best out of all of these because I found the language easy to learn, it did everything I needed, and I really liked the tight integration of the plotting utilities that didn’t feel like an afterthought or kluged-on library.

      Since then I’ve used R for many things for which there were probably better solutions simply because I’m familiar with it. It works for me, and I can make it do useful things without too much effort.

    2. If you’re bloody-minded enough, R with ggplot gives you very granular abilities to make the charts you want.

      I hadn’t even considered using R with RaspPi. With some low-power peripherals and enough silicone, that might be a great package for the “event epis” to pack into the worst field conditions.

  3. R has a number of things going for it. It gets dates and time right and there are no floating point errors. It can eat almost any code you feed it if you have the right libraries. There are lots of ready made tools for free if you can pick the right one for your problem.

    I have found R to be the best file management tool ever. Call:
    c.drive<-file.info(dir('C:\',all.files = FALSE, full.names =T, recursive = T, include.dirs = T))[1:4]
    or c.drive$Name[grep('to_find',c.drive$Name)]
    Really comes in handy and sure would be nice to have tools like that on the Raspberry Pi.

    I find R easy to use as glue for both shell calls, system calls and to programs I write in C.

    I am concerned about how R will preform on slow small platforms. Experience tells me porting things down to smaller computers doesn't come out well due to all the code bloat they accumulate with time. I hope that not true for R as its recently gone through a major speed up effort.

    I am bit parinod about size and seed I still write
    x =3
    rather than for(x=3;x<0; x–){}
    Because it saves 1 machine cycle on most CPU's every time thought loop.

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.