Skip to content

Commit

Permalink
Merge pull request #6 from terceiro/r-home
Browse files Browse the repository at this point in the history
Embed the R directory in the compiled extension
  • Loading branch information
alexgutteridge committed Nov 29, 2011
2 parents 57c62ff + 65079ce commit 66b9c0f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
9 changes: 9 additions & 0 deletions ext/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,13 @@
exit 1
end

File.open("config.h", "w") do |f|
f.puts("#ifndef R_CONFIG_H")
f.puts("#define R_CONFIG_H")
r_home = $configure_args.has_key?('--with-R-dir') ? $configure_args['--with-R-dir'].inspect : 'NULL'
f.puts("#define RSRUBY_R_HOME #{r_home}")
f.puts("#endif")
end
$extconf_h = 'config.h'

create_makefile("rsruby_c")
5 changes: 5 additions & 0 deletions ext/rsruby.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
*/

#include "rsruby.h"
#include "config.h"
#include <stdlib.h>

/* Global list to protect R objects from garbage collection */
/* This is inspired in $R_SRC/src/main/memory.c */
Expand Down Expand Up @@ -139,6 +141,9 @@ void init_R(int argc, char **argv){

char *defaultArgv[] = {"rsruby","-q","--vanilla"};

if (RSRUBY_R_HOME) {
setenv("R_HOME", RSRUBY_R_HOME, 0);
}
Rf_initEmbeddedR(sizeof(defaultArgv) / sizeof(defaultArgv[0]), defaultArgv);
R_Interactive = FALSE; //Remove crash menu (and other interactive R features)
}
Expand Down

0 comments on commit 66b9c0f

Please sign in to comment.