Re: [Rd] Qs on calling R from C

From: Kynn Jones <>
Date: Sat, 06 Jun 2009 18:23:03 -0400

On Sat, Jun 6, 2009 at 5:31 PM, Dirk Eddelbuettel <> wrote:


> Try reading 'R Extensions' section 8.1 entitled 'Embedding R under
> Unix-alikes'.

That was just what I needed! All it took was adding a single line before the call to mkString (and adding one more header file):

#include <Rinternals.h>
#include <Rembedded.h>

SEXP hello() {
  return mkString("Hello, world!\n");

int main(int argc, char **argv) {
  SEXP x;
  Rf_initEmbeddedR(argc, argv);
  x = hello();
  return x == NULL; /* i.e. 0 on success */ }

When I run the executable with

% myR/bin/R CMD hello_r -q --vanilla goes without a hitch.

Many thanks!


        [[alternative HTML version deleted]] mailing list Received on Sat 06 Jun 2009 - 22:27:01 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sun 07 Jun 2009 - 21:36:08 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive