Skip to content

Commit 66b9c0f

Browse files
Merge pull request #6 from terceiro/r-home
Embed the R directory in the compiled extension
2 parents 57c62ff + 65079ce commit 66b9c0f

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

ext/extconf.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,13 @@
2626
exit 1
2727
end
2828

29+
File.open("config.h", "w") do |f|
30+
f.puts("#ifndef R_CONFIG_H")
31+
f.puts("#define R_CONFIG_H")
32+
r_home = $configure_args.has_key?('--with-R-dir') ? $configure_args['--with-R-dir'].inspect : 'NULL'
33+
f.puts("#define RSRUBY_R_HOME #{r_home}")
34+
f.puts("#endif")
35+
end
36+
$extconf_h = 'config.h'
37+
2938
create_makefile("rsruby_c")

ext/rsruby.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
*/
3131

3232
#include "rsruby.h"
33+
#include "config.h"
34+
#include <stdlib.h>
3335

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

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

144+
if (RSRUBY_R_HOME) {
145+
setenv("R_HOME", RSRUBY_R_HOME, 0);
146+
}
142147
Rf_initEmbeddedR(sizeof(defaultArgv) / sizeof(defaultArgv[0]), defaultArgv);
143148
R_Interactive = FALSE; //Remove crash menu (and other interactive R features)
144149
}

0 commit comments

Comments
 (0)