Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Compiled source #
###################
*.com
*.class
*.dll
*.exe
*.o
*.so
*.pyc

# Logs and databases #
######################
*.log

# OS generated files #
######################
.DS_Store*
ehthumbs.db
Icon?
Thumbs.db
2 changes: 1 addition & 1 deletion License.txt
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ such a program is covered only if its contents constitute a work based
on the Library (independent of the use of the Library in a tool for
writing it). Whether that is true depends on what the Library does
and what the program that uses the Library does.

1. You may copy and distribute verbatim copies of the Library's
complete source code as you receive it, in any medium, provided that
you conspicuously and appropriately publish on each copy an
Expand Down
6 changes: 3 additions & 3 deletions examples/arrayfields.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#unlike the R datatypes.
#
#To better replicate the R behaviour, this code uses the arrayfields library
#(available as a gem) and the RSRuby Proc conversion mode to create named
#(available as a gem) and the RSRuby Proc conversion mode to create named
#Arrays which preserve order.
#
#NB: You can run this file like a normal Ruby script. I use some post-
Expand All @@ -22,7 +22,7 @@
#
#The next Proc takes the R object and generates a new Array with fields
#set appropriately:
#
#
# conv_proc = lambda{|x|
# hash = x.to_ruby
# array = []
Expand All @@ -37,7 +37,7 @@
# r = RSRuby.instance
# r.t_test.autoconvert(RSRuby::PROC_CONVERSION)
# r.proc_table[test_proc] = conv_proc
#
#
#The return values from t.test are now Arrays rather than Hashes:
#
# ttest = r.t_test([1,2,3])
Expand Down
2 changes: 1 addition & 1 deletion examples/bioc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#
# r.library('affy')
#
# r.eval_R("mydata <- ReadAffy()")
# r.eval_R("mydata <- ReadAffy()")
# r.eval_R("eset.rma <- rma(mydata)")
# r.eval_R("eset.pma <- mas5calls(mydata)")
#
Expand Down
54 changes: 27 additions & 27 deletions ext/Converters.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ SEXP ruby_to_R(VALUE obj)
return R_NilValue;
}

//If object has 'as_r' then call it and use
//If object has 'as_r' then call it and use
//returned value subsequently
if (rb_respond_to(obj, rb_intern("as_r"))){
obj = rb_funcall(obj,rb_intern("as_r"),0);
if (!obj)
return NULL;
}

if (Robj_Check(obj))
{
Data_Get_Struct(obj, struct SEXPREC, robj);
Expand All @@ -67,9 +67,9 @@ SEXP ruby_to_R(VALUE obj)
} else {
LOGICAL_DATA(robj)[0] = FALSE;
}

}
else if (TYPE(obj) == T_FIXNUM ||
else if (TYPE(obj) == T_FIXNUM ||
TYPE(obj) == T_BIGNUM)
{
PROTECT(robj = NEW_INTEGER(1));
Expand All @@ -80,26 +80,26 @@ SEXP ruby_to_R(VALUE obj)
PROTECT(robj = NEW_NUMERIC(1));
NUMERIC_DATA(robj)[0] = NUM2DBL(obj);
}
else if (RubyComplex_Check(obj))
else if (RubyComplex_Check(obj))
{
PROTECT(robj = NEW_COMPLEX(1));
COMPLEX_DATA(robj)[0].r = NUM2DBL(rb_funcall(obj,rb_intern("real"),0));
COMPLEX_DATA(robj)[0].i = NUM2DBL(rb_funcall(obj,rb_intern("image"),0));
}
else if (!NIL_P(rb_check_string_type(obj)))
else if (!NIL_P(rb_check_string_type(obj)))
{
PROTECT(robj = NEW_STRING(1));
SET_STRING_ELT(robj, 0, COPY_TO_USER_STRING(RSTRING_PTR(obj)));
}
else if (!NIL_P(rb_check_array_type(obj)))
else if (!NIL_P(rb_check_array_type(obj)))
{
PROTECT(robj = array_to_R(obj));
}
else if (TYPE(obj) == T_HASH)
else if (TYPE(obj) == T_HASH)
{
PROTECT(robj = hash_to_R(obj));
}
else
else
{
str = rb_funcall(obj,rb_intern("inspect"),0);
str = rb_funcall(str,rb_intern("slice"),2,INT2NUM(0),INT2NUM(60));
Expand All @@ -121,7 +121,7 @@ SEXP array_to_R(VALUE obj)

/* This matrix defines what mode a vector should take given what
it already contains and a new item

E.g. Row 0 indicates that if we've seen an any, the vector will
always remain an any. Row 3 indicates that if we've seen a
float, then seeing an boolean, integer, or float will preserve
Expand All @@ -137,7 +137,7 @@ SEXP array_to_R(VALUE obj)
{0, 0, 0, 0, 0, 5, 0}, // string
{0, 0, 0, 0, 0, 0, 6} // RObj
};

//Probably unnessecary but just in case
obj = rb_check_array_type(obj);

Expand All @@ -158,7 +158,7 @@ SEXP array_to_R(VALUE obj)

if (!(rit = ruby_to_R(it)))
goto exception;

SET_VECTOR_ELT(robj, i, rit);
}

Expand Down Expand Up @@ -207,7 +207,7 @@ hash_to_R(VALUE obj)
return NULL;
if (!(values = rb_funcall(obj,rb_intern("values"),0)))
return NULL;

if (!(robj = array_to_R(values)))
goto fail;
if (!(names = array_to_R(keys)))
Expand All @@ -228,7 +228,7 @@ type_to_int(VALUE obj)
{
if (obj == Qtrue || obj == Qfalse)
return BOOL_T;
else if (TYPE(obj) == T_FIXNUM ||
else if (TYPE(obj) == T_FIXNUM ||
TYPE(obj) == T_BIGNUM)
return INT_T;
else if (TYPE(obj) == T_FLOAT)
Expand Down Expand Up @@ -271,7 +271,7 @@ VALUE to_ruby_with_mode(SEXP robj, int mode)
if (i<0) return Qnil;
if (i==1) break;
default:
obj = Data_Wrap_Struct(rb_const_get(rb_cObject,
obj = Data_Wrap_Struct(rb_const_get(rb_cObject,
rb_intern("RObj")), 0, 0, robj);
rb_iv_set(obj,"@conversion",INT2FIX(TOP_MODE));
rb_iv_set(obj,"@wrap",Qfalse);
Expand Down Expand Up @@ -325,7 +325,7 @@ to_ruby_vector(SEXP robj, VALUE *obj, int mode)
len = GET_LENGTH(robj);
tmp = rb_ary_new2(len);
type = TYPEOF(robj);

for (i=0; i<len; i++) {
switch (type)
{
Expand Down Expand Up @@ -438,11 +438,11 @@ from_proc_table(SEXP robj, VALUE *fun)
funs = rb_funcall(proc_table,rb_intern("values"),0);
l = FIX2INT(rb_funcall(proc_table,rb_intern("size"),0));

obj = Data_Wrap_Struct(rb_const_get(rb_cObject,
obj = Data_Wrap_Struct(rb_const_get(rb_cObject,
rb_intern("RObj")), 0, 0, robj);
rb_iv_set(obj,"@conversion",INT2FIX(TOP_MODE));
rb_iv_set(obj,"@wrap",Qfalse);

error = 0;
for (i=0; i<l; i++) {
proc = rb_ary_entry(procs, i);
Expand Down Expand Up @@ -475,7 +475,7 @@ VALUE reset_mode(VALUE mode){

rb_iv_set(RSRUBY,
"@default_mode",
mode);
mode);

return Qnil;

Expand All @@ -501,7 +501,7 @@ to_ruby_proc(SEXP robj, VALUE *obj)

//Create new object based on robj and call the function
//found above with it as argument
tmp = Data_Wrap_Struct(rb_const_get(rb_cObject,
tmp = Data_Wrap_Struct(rb_const_get(rb_cObject,
rb_intern("RObj")), 0, 0, robj);
rb_iv_set(tmp,"@conversion",INT2FIX(TOP_MODE));
rb_iv_set(tmp,"@wrap",Qfalse);
Expand Down Expand Up @@ -563,13 +563,13 @@ to_ruby_class(SEXP robj, VALUE *obj)
VALUE args[2];

fun = from_class_table(robj);

if (fun==Qnil)
return 0; /* conversion failed */
tmp = Data_Wrap_Struct(rb_const_get(rb_cObject,

tmp = Data_Wrap_Struct(rb_const_get(rb_cObject,
rb_intern("RObj")), 0, 0, robj);
rb_iv_set(tmp,"@conversion",INT2FIX(TOP_MODE));
rb_iv_set(tmp,"@conversion",INT2FIX(TOP_MODE));
rb_iv_set(tmp,"@wrap",Qfalse);

//Again set conversion mode to basic to prevent recursion
Expand Down Expand Up @@ -601,7 +601,7 @@ VALUE to_ruby_hash(VALUE obj, SEXP names)
name = CHAR(STRING_ELT(names, i));
rb_hash_aset(hash, rb_str_new2(name), it);
}

return hash;
}

Expand All @@ -620,7 +620,7 @@ VALUE ltranspose(VALUE list, int *dims, int *strides,
for (i=0; i<dims[pos]; i++) {
if (!(it = rb_ary_entry(list, i*strides[pos]+shift)))
return Qnil;
rb_ary_store(nl, i, it);
rb_ary_store(nl, i, it);
}
return nl;
}
Expand All @@ -634,7 +634,7 @@ VALUE ltranspose(VALUE list, int *dims, int *strides,

return nl;
}

/* Convert a R Array to a Ruby Array (in the form of
* array of arrays of ...) */
VALUE to_ruby_array(VALUE obj, int *dims, int l)
Expand Down
6 changes: 3 additions & 3 deletions ext/R_eval.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ SEXP do_eval_expr(SEXP e) {
rb_raise(rb_eInterrupt,"RSRuby interrupted");
}
else {
rb_eRException = rb_const_get(rb_cObject,
rb_eRException = rb_const_get(rb_cObject,
rb_intern("RException"));
rb_raise(rb_eRException, get_last_error_msg());
return NULL;
Expand Down Expand Up @@ -105,7 +105,7 @@ SEXP get_fun_from_name(char *ident) {
rb_raise(rb_eRuntimeError, "symbol print-name too long");
return NULL;
}

#if R_VERSION < 0x20000
obj = Rf_findVar(Rf_install(ident), R_GlobalEnv);
#else
Expand All @@ -127,7 +127,7 @@ SEXP get_fun_from_name(char *ident) {
if (obj != R_UnboundValue)
obj = Rf_findFun(Rf_install(ident), R_GlobalEnv);
#endif

if (obj == R_UnboundValue) {
rb_raise(rb_eNoMethodError, "R Function \"%s\" not found", ident);
return NULL;
Expand Down
6 changes: 3 additions & 3 deletions ext/robj.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ make_argl(VALUE args, SEXP *e)

//Ensure we have an array
args = rb_check_array_type(args);

for (i=0; i<RARRAY_LEN(args); i++) {
pair = rb_ary_entry(args, i);
pair = rb_check_array_type(pair);
Expand All @@ -146,7 +146,7 @@ make_argl(VALUE args, SEXP *e)
/* Name must be a string. If it is empty string '' then no name*/
name = rb_ary_entry(pair, 0);
name = StringValue(name);
name = rb_funcall(rb_const_get(rb_cObject,
name = rb_funcall(rb_const_get(rb_cObject,
rb_intern("RSRuby")),
rb_intern("convert_method_name"),1,name);

Expand All @@ -158,7 +158,7 @@ make_argl(VALUE args, SEXP *e)
SETCAR(*e, rvalue);

/* Add name (if present) */
if (RSTRING_LEN(name) > 0)
if (RSTRING_LEN(name) > 0)
{
SET_TAG(*e, Rf_install(RSTRING_PTR(name)));
}
Expand Down
34 changes: 17 additions & 17 deletions ext/rsruby.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ RecursiveRelease(SEXP obj, SEXP list)
Robj_dealloc(VALUE self)
{
SEXP robj;

Data_Get_Struct(self, struct SEXPREC, robj);

R_References = RecursiveRelease(robj, R_References);
SET_SYMVALUE(install("R.References"), R_References);

return;
}*/

Expand All @@ -83,7 +83,7 @@ VALUE get_fun(VALUE self, VALUE name){
return Qnil;

/* Wrap the returned R object as a ruby Object */
rubyobj = Data_Wrap_Struct(rb_const_get(rb_cObject,
rubyobj = Data_Wrap_Struct(rb_const_get(rb_cObject,
rb_intern("RObj")), 0, 0, robj);
rb_iv_set(rubyobj,"@conversion",INT2FIX(conversion));
rb_iv_set(rubyobj,"@wrap",Qfalse);
Expand All @@ -97,17 +97,17 @@ void r_finalize(void)
{
unsigned char buf[1024];
char * tmpdir;
R_dot_Last();
R_RunExitFinalizers();
CleanEd();
Rf_KillAllDevices();

if((tmpdir = getenv("R_SESSION_TMPDIR"))) {
snprintf((char *)buf, 1024, "rm -rf %s", tmpdir);
R_system((char *)buf);

R_dot_Last();
R_RunExitFinalizers();
CleanEd();
Rf_KillAllDevices();

if((tmpdir = getenv("R_SESSION_TMPDIR"))) {
snprintf((char *)buf, 1024, "rm -rf %s", tmpdir);
R_system((char *)buf);
}

PrintWarnings(); /* from device close and .Last */
R_gc(); /* Remove any remaining R objects from memory */
}
Expand Down Expand Up @@ -149,12 +149,12 @@ void init_R(int argc, char **argv){
Rf_initEmbeddedR(sizeof(defaultArgv) / sizeof(defaultArgv[0]), defaultArgv);
R_Interactive = FALSE; //Remove crash menu (and other interactive R features)
}

/* This method is for testing catching of segfaults */
VALUE crash(){
int* ptr = (int*)0;
*ptr = 1;
return Qtrue;
return Qtrue;
}


Expand All @@ -176,7 +176,7 @@ void Init_rsruby_c(){
//Add the lcall method to RObj
cRObj = rb_const_get(rb_cObject,rb_intern("RObj"));
rb_define_method(cRObj, "lcall", RObj_lcall, 1);
rb_define_method(cRObj, "__init_lcall__", RObj_init_lcall, 1);
rb_define_method(cRObj, "__init_lcall__", RObj_init_lcall, 1);
rb_define_method(cRObj, "to_ruby", RObj_to_ruby, -2);

}
Loading