Skip to content

[Rcpp-devel] new to R, so don't understand Rcpp limits

2 messages · George Coles, Dirk Eddelbuettel

#
Hi,
 I have recently been writing a lot of c++. I have been a big python user
the last couple of years, and never really use R but have it installed.

I need to share some data between my Python code and my c++ code, C++ does
not really have a lot of nice ideas like DataFrames. But if you save a
dataframe from Python into csv, you can readily read it using R. Csv is not
the best way to go, but it is a simple case.

I have generally been noticing as I google around, that R has a healthy and
seemingly growing list of packages that can be accessed by c++ code. From
c++, R does not look so bad to me, and I would like to get access to this
large library of native routines in R.

First on the list, is that I hope to read a dataframe or something like it
from data in a file, and then transform that dataframe or other tabular
object into something I can use in my c++ code for linear algebra, like an
Armadillo matrix.

So is there any native code in the R world that I can use to read a
dataframe from a file?

please forgive my ignorance. I think Rcpp is really cool, it might make me
a backdoor R user.

thx
George Coles
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20170803/17afd8b1/attachment.html>
#
On 3 August 2017 at 11:30, George Coles wrote:
| Hi,
|  I have recently been writing a lot of c++. I have been a big python user
| the last couple of years, and never really use R but have it installed.

Coming from a common base is not a bad starting point at all.  See my
RcppAnnoy package on top of the C++ (with Python glue) Annoy package, and
also see https://cran.r-project.org/package=fastcluster which "comes with"
Python and R bindings.
 
| I need to share some data between my Python code and my c++ code, C++ does
| not really have a lot of nice ideas like DataFrames. But if you save a
| dataframe from Python into csv, you can readily read it using R. Csv is not
| the best way to go, but it is a simple case.

CSVs are indeed a terrible format, yet annoyingly common. Try binary
alternatives if you can.

There are feather and Apache arrow for 'data.frame' reimplementations usable
from both R and Python...

Lastly, there is now reticulate (on CRAN) to access Python from R.

| I have generally been noticing as I google around, that R has a healthy and
| seemingly growing list of packages that can be accessed by c++ code. From
| c++, R does not look so bad to me, and I would like to get access to this
| large library of native routines in R.
| 
| First on the list, is that I hope to read a dataframe or something like it
| from data in a file, and then transform that dataframe or other tabular
| object into something I can use in my c++ code for linear algebra, like an
| Armadillo matrix.
| 
| So is there any native code in the R world that I can use to read a
| dataframe from a file?
| 
| please forgive my ignorance. I think Rcpp is really cool, it might make me
| a backdoor R user.

Poke around the examples, and eg the Rcpp Gallery (at gallery.rcpp.org).  The
seamless passage from R to C++ and back is really, really useful and smooth.
JJ and I have riffing for years on the need for a talk on 'R as C++ shell'.
No time for that yet though :)

Cheers, Dirk