Calling C for R?

Asked

Viewed 68 times

1

How do I program in C inside the R or call a code of C in R?

I’ve read a few tutorials, but I don’t quite understand.

  • 1

    Usually the C code is compiled, so you will either have a lib or an executable binary. I don’t know about R, but the logic to use C seems more like.

  • 1

    @Guilhermenascimento From what I understand of this tutorial is right there. Wagner, would you have any example of material that you consulted and that still left you doubtful? If the link I posted is enough, I can translate and post as a response, otherwise please tell me which aspect is bringing you more difficulty.

  • 1

    @mgibsonbr Great link. I don’t know if I’m right, but maybe he didn’t understand the dyn.load("foo.so"), since .so (or . Sl) is usually an extension that identifies the "equivalents" of windows dlls on like-Unix systems. Maybe because they are windows user, did not understand, I think we can already formulate a quick answer :) I just do not do it because I do not know R. In the case of Windows would be something like dyn.load("foo.dll")? I saw that there are also in R the methods .C, .Call, .Fortran and .External. -- If you answer, you already have my +1 guaranteed

  • @Guilhermenascimento Unfortunately I also do not know R... :( I imagine - when reading the previous link - that the R executable itself is already in charge of compiling the C code for a .so, using the tools already available in *NIX (gcc, etc.). But I do not know if he has the ability to do this in Windows, which as far as I know does not come with a C compiler by default (requiring additional settings, which I do not know, also not having experience with R).

  • I don’t think so, I believe I have to compile it beforehand, it seems that the .C serves only to call a function. This looks like good documentation: http://www.inside-r.org/r-doc/base/.C - Even using QT (c++ and mingw) in my case I went to try to use Hunspell once, I thought QT itself would compile everything together, but nothing worked, so I had to compile for one. lib and pass the QT mingw parameters. But I’m not sure @mgibsonbr

  • @Guilhermenascimento I’m not talking about .C, but of command R CMD SHLIB foo.c (and after the include dyn.load("foo.so")). He must do most of the "magic" - in a POSIX system at least.

  • Hi William, I used the same link that you posted, but I got into it (rsrs).

  • @mgibsonbr I understood, I had not realized it, I only assumed by the experience with other platforms, it must be this same, maybe he did not configure the R correctly in the environment PATH.

  • @Wagnerjorge which system, correctly installed the R?

  • I installed on Windows and is giving error: Error 1 occurred building Shared library.

  • Fixing the previous comment: Installed on Windows, R is working normally (I use basically R for a while now), but to put code C++ and C is giving the error: Error 1 occurred building Shared library.

  • 1

    Take a look at this package: http://www.rcpp.org/ This chapter is also good: http://adv-r.had.co.nz/Rcpp.html

Show 7 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.