I'll try to answer this question as well as I can.
...but the question your NOT asking is perhaps more relevant: Can the R algorithm be made faster in R? The answer here is usually "yes". Can it be "fast enough"? Well, that is impossible to answer without trying (and seeing the current R code).
Q: Will my R algorithm be faster in C?
A: Yes! If you write the "best" C code for the algorithm, it will most likely be faster. It will most likely also be a lot more work to do so.
Q: Can sorting of large vectors be done faster in C?
A: Yes. Using multi-threading, you can improve the speed quite a lot. ...But start by calling sort(x, method='quick')
in R and see if that improves things! The default method isn't very fast for random data.
x <- runif(1e7)
system.time( sort(x) ) # 2.50 secs
system.time( sort(x, method='quick') ) # 1.37 secs
#system.time( tommysort(x) ) # 0.51 secs (4 threads)
Q: What libraries mimic basic R functions?
A: LAPACK/BLAS handles matrix math in R. If that's all you need, you can find libraries that are much faster than the vanilla ones in R (you can use some of them in R too to improve performance!).
More info on BLAS
Another way is to make a .Call from R to C and from there you have access to all of R's functionality! The inline
package and the Rcpp
package can help make it easier.
A third way is to embed R in your application. Rinside
can help make that easier.
Q: How do I read CSV data into C?
A: Look at the fopen
and fscanf
functions. ...and use them to write a data import function.