Recording from a USB Port in RStudio

Hello All!

I am currently trying to get R to read some voltage data incoming from a DAQ hooked up to my computer by a USB port. I am having trouble finding code to record from a USB device, let along the voltage information. Does anyone know a good way to record information from a USB and have the raw data get recorded in R?

The end goal is recording time varying voltage with my USB through RStudio.

Hope that helps and if not I can further clarify anything!


Phineas Packard
As a fan of the Arduino I wonder whether R is the right tool for the Job. Python has some existing libraries like serial which might do the job (might be able to even do it directly from a terminal window on a unix system). IF that works you could use something like rPython to call your python code from R.


Probably A Mammal
I agree. If you're trying to read the low level system information coming through your USB, you'll want to use the right tools. R is for statistical data analysis, it's not a multipurpose tool for systems programming. Now, you could use something like Rcpp to write the systems programming in C++ and pipe it directly into and through R. However, I'd probably go the route of a data pipeline that uses Python as Lazar suggested.

I don't quite understand why you want R to handle all of this, either, besides "doing this in RStudio." Do you want to have some sort of visualization or dashboard or analytics off of this information or are you just trying to capture the information? As I said, R is not the right tool for this capture. If you want to produce visualizations or some data discovery, then certainly tapping R onto the end of this pipeline for that make sense. So it really comes down to what you're trying to make this pipeline accomplish

[Sensor] -> [Python Capture] -> [Python Clean and Store (file?)] -> [R Processing and Viz]

If you don't need the last part or even the cleaning, then just focus on capture.
I see where you are coming from. I was recommended to try this by a friend who believed the data acquisition could be done through R (and I just happened to have RStudio on my computer).

So based off your advice, it would be best to use Python to collect the data, then once collected it could be moved to R (or anywhere else) for data analysis.


Probably A Mammal
Right. I mean, you can do a multi-step pipeline, which isn't a bad idea (the "unix" approach to giving each task its own execution so you pipe results from one task into the next). However, you can completely do everything in Python, including executing R scripts on that data or do a Python-based analysis, since it has libraries for handling that stuff pretty well now, also (pandas, matplotlib). Or you can do everything within R if you want to basically build the pipeline in C++ and then plug that into your R scripts using the Rcpp package.