diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ac8f968 --- /dev/null +++ b/.gitignore @@ -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 diff --git a/License.txt b/License.txt index 5ab7695..602bfc9 100644 --- a/License.txt +++ b/License.txt @@ -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 diff --git a/examples/arrayfields.rb b/examples/arrayfields.rb index c8991e5..362580c 100644 --- a/examples/arrayfields.rb +++ b/examples/arrayfields.rb @@ -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- @@ -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 = [] @@ -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]) diff --git a/examples/bioc.rb b/examples/bioc.rb index 27d1fed..97daaca 100644 --- a/examples/bioc.rb +++ b/examples/bioc.rb @@ -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)") # diff --git a/ext/Converters.c b/ext/Converters.c index c19cd2c..8ecb447 100644 --- a/ext/Converters.c +++ b/ext/Converters.c @@ -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); @@ -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)); @@ -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)); @@ -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 @@ -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); @@ -158,7 +158,7 @@ SEXP array_to_R(VALUE obj) if (!(rit = ruby_to_R(it))) goto exception; - + SET_VECTOR_ELT(robj, i, rit); } @@ -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))) @@ -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) @@ -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); @@ -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 0) + if (RSTRING_LEN(name) > 0) { SET_TAG(*e, Rf_install(RSTRING_PTR(name))); } diff --git a/ext/rsruby.c b/ext/rsruby.c index 40e5cab..d197f6a 100644 --- a/ext/rsruby.c +++ b/ext/rsruby.c @@ -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; }*/ @@ -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); @@ -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 */ } @@ -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; } @@ -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); } diff --git a/ext/rsruby.h b/ext/rsruby.h index 905f4e1..266c07c 100644 --- a/ext/rsruby.h +++ b/ext/rsruby.h @@ -58,10 +58,10 @@ /* Missing definitions from Rinterface.h or RStartup.h */ # define CleanEd Rf_CleanEd -extern int Rf_initEmbeddedR(int argc, char **argv); +extern int Rf_initEmbeddedR(int argc, char **argv); extern int R_Interactive; extern void CleanEd(void); -extern int R_CollectWarnings; +extern int R_CollectWarnings; # define PrintWarnings Rf_PrintWarnings extern void PrintWarnings(void); @@ -75,7 +75,7 @@ SEXP RecursiveRelease(SEXP obj, SEXP list); VALUE rs_shutdown(VALUE self); VALUE get_fun(VALUE self, VALUE name); -VALUE rr_init(VALUE self); +VALUE rr_init(VALUE self); VALUE crash(void); diff --git a/lib/rsruby.rb b/lib/rsruby.rb index 91f3f78..ff981d9 100644 --- a/lib/rsruby.rb +++ b/lib/rsruby.rb @@ -6,20 +6,20 @@ #== Synopsis # -#This class represents the embedded R interpreter. The Singleton module is -#mixed in to ensure that only one R interpreter is running in a script at +#This class represents the embedded R interpreter. The Singleton module is +#mixed in to ensure that only one R interpreter is running in a script at #any one time and that the interpreter can always be easily accessed without -#using a global variable. +#using a global variable. # -#The R interpreter is started by calling RSRuby.instance. The returned -#object represents the R interpreter and R functions are called by +#The R interpreter is started by calling RSRuby.instance. The returned +#object represents the R interpreter and R functions are called by #calling methods on this object: # # r = RSRuby.instance # r.sum(1,2,3) # puts r.t_test(1,2,3)['p-value'] # -#See the manual[http://web.kuicr.kyoto-u.ac.jp/~alexg/rsruby/manual.pdf] for +#See the manual[http://web.kuicr.kyoto-u.ac.jp/~alexg/rsruby/manual.pdf] for #more details on calling functions and the conversion system for passing data #between Ruby and R. If no suitable conversion from R to Ruby is found, an RObj #is returned (all R functions are returned as instances of RObj). @@ -80,17 +80,17 @@ def initialize() @class_table = {} @proc_table = {} - + @caching = true reset_cache - + #Catch errors self.__init_eval_R__("options(error=expression(NULL))") #disable errors self.__init_eval_R__("options(show.error.messages=F)") end - + def reset_cache #Setup R object cache @cache = {} @@ -106,11 +106,11 @@ def reset_cache @cache['NA'] = self.__init_eval_R__('NA') @cache['NaN'] = self.__init_eval_R__('NaN') # @cache['NAN'] = self.eval_R('as.double(NA)') - + #help! @cache['helpfun'] = self.with_mode(NO_CONVERSION, self.__getitem__('help',true)) end - + #Delete an R object from the cache. Use R-style function naming, not ruby style. def delete_from_cache(x) @cache.delete(x) @@ -142,8 +142,8 @@ def method_missing(r_id,*args) #convert arguments to lcall format lcall_args = RSRuby.convert_args_to_lcall(args) - - #Return result of calling object with lcall + + #Return result of calling object with lcall #formatted args return robj.lcall(lcall_args) @@ -151,7 +151,7 @@ def method_missing(r_id,*args) return robj - end + end #The same as method_missing, but only returns the R function/object, #does not call it. @@ -159,10 +159,10 @@ def [](r_id) #Translate Ruby method call to R robj_name = RSRuby.convert_method_name(r_id.to_s) - + #Retrieve it robj = self.__getitem__(robj_name) - + #And return it return robj @@ -175,7 +175,7 @@ def with_mode(mode,func) return func end - #Converts a String representing a 'Ruby-style' R function name into a + #Converts a String representing a 'Ruby-style' R function name into a #String with the real R name according to the rules given in the manual. def RSRuby.convert_method_name(name) if name.length > 1 and name[-1].chr == '_' and name[-2].chr != '_' @@ -186,20 +186,20 @@ def RSRuby.convert_method_name(name) return name end - #Converts an Array of function arguments into lcall format. If the last - #element of the array is a Hash then the contents of the Hash are + #Converts an Array of function arguments into lcall format. If the last + #element of the array is a Hash then the contents of the Hash are #interpreted as named arguments. # - #The returned value is an Array of tuples (Arrays of length two). Each + #The returned value is an Array of tuples (Arrays of length two). Each #tupple corresponds to a name/argument pair. # #For example: - # convert_args_to_lcall([1,2,3,{:a=>4,:b=>5}) + # convert_args_to_lcall([1,2,3,{:a=>4,:b=>5}) # => [['',1],['',2],['',3],['a',4],['b',5]] def RSRuby.convert_args_to_lcall(args) lcall_args = [] - + args.each_with_index do |arg,i| unless arg.kind_of?(Hash) and i == args.length-1 lcall_args.push(['',arg]) diff --git a/lib/rsruby/dataframe.rb b/lib/rsruby/dataframe.rb index 9727802..5697293 100644 --- a/lib/rsruby/dataframe.rb +++ b/lib/rsruby/dataframe.rb @@ -4,14 +4,14 @@ #== Synopsis # #This is an extended ERObj class inspired by the example given in the RPy -#manual used for R data frames. -#As with ERObj, methods caught by method_missing are converted into attribute +#manual used for R data frames. +#As with ERObj, methods caught by method_missing are converted into attribute #calls on the R dataframe it represents. The rows and columns methods give #access to the column and row names. # #== Usage # -#See examples/dataframe.rb[link:files/examples/dataframe_rb.html] for +#See examples/dataframe.rb[link:files/examples/dataframe_rb.html] for #examples of usage. # #-- @@ -74,10 +74,10 @@ def columns def[]=(row,col,val) #How to set a value in this dataframe? @r.assign("rsrubytemp",@robj) - + ### VERY HACKY - This relies on val having the same #string representation in R and Ruby. An assign based - #solution with proper conversion of val would be much + #solution with proper conversion of val would be much #better @r.eval_R("rsrubytemp[#{row+1},#{col+1}] <- #{val}") # diff --git a/lib/rsruby/erobj.rb b/lib/rsruby/erobj.rb index 06c3cb9..9fc2238 100644 --- a/lib/rsruby/erobj.rb +++ b/lib/rsruby/erobj.rb @@ -9,7 +9,7 @@ # #== Usage # -#See examples/erobj.rb[link:files/examples/erobj_rb.html] for examples of +#See examples/erobj.rb[link:files/examples/erobj_rb.html] for examples of #usage. # #-- @@ -92,7 +92,7 @@ def to_s end - #Methods caught by method_missing are converted into attribute calls on + #Methods caught by method_missing are converted into attribute calls on #the R object it represents. def method_missing(attr) mode = RSRuby.get_default_mode diff --git a/lib/rsruby/robj.rb b/lib/rsruby/robj.rb index ed591d3..a626b14 100644 --- a/lib/rsruby/robj.rb +++ b/lib/rsruby/robj.rb @@ -1,9 +1,9 @@ #== Synopsis # -#This class represents a reference to an object in the R interpreter. It +#This class represents a reference to an object in the R interpreter. It #also holds a conversion mode used if the RObj represents a callable function. -#RObj objects can be passed to R functions called from Ruby and are the -#default return type if RSRuby cannot convert the returned results of an R +#RObj objects can be passed to R functions called from Ruby and are the +#default return type if RSRuby cannot convert the returned results of an R #function. # #-- @@ -59,7 +59,7 @@ def autoconvert(m=false) raise ArgumentError if m < -1 or m > RSRuby::TOP_CONVERSION @conversion = m end - @conversion + @conversion end end diff --git a/manual.tex b/manual.tex index 4f4f42c..6e6c0e3 100644 --- a/manual.tex +++ b/manual.tex @@ -81,13 +81,13 @@ \section{Installation} \item First, ensure that the |R_HOME| environment variable is set correctly. On my Ubuntu linux machine this is: -\begin{Verbatim} +\begin{Verbatim} R_HOME=/usr/lib/R \end{Verbatim} While on OS X it is: -\begin{Verbatim} +\begin{Verbatim} R_HOME=/Library/Frameworks/R.framework/Resources \end{Verbatim} @@ -155,10 +155,10 @@ \section{Getting Started: A Small Example} \begin{Verbatim} irb> r.wilcox_test([1,2,3],[4,5,6]) -=> {"p.value"=>0.1, "null.value"=>{"mu"=>0.0}, - "data.name"=>"c(1, 2, 3) and c(4, 5, 6)", - "method"=>"Wilcoxon rank sum test", - "alternative"=>"two.sided", "parameter"=>nil, +=> {"p.value"=>0.1, "null.value"=>{"mu"=>0.0}, + "data.name"=>"c(1, 2, 3) and c(4, 5, 6)", + "method"=>"Wilcoxon rank sum test", + "alternative"=>"two.sided", "parameter"=>nil, "statistic"=>{"W"=>0.0}} \end{Verbatim} @@ -166,7 +166,7 @@ \chapter{Accessing R From Ruby} \section{Looking Up R Objects From Ruby} -R functions and variables are both accessed from Ruby in the same way. Unlike in Ruby, R variables and functions cannot share the same name, so there is no possibility of accessing a function when you meant to access a variable (except by user error). +R functions and variables are both accessed from Ruby in the same way. Unlike in Ruby, R variables and functions cannot share the same name, so there is no possibility of accessing a function when you meant to access a variable (except by user error). Similarly to RPy, there are two methods for accessing R objects from Ruby. However, unlike RPy, the two methods are not exactly equivalent so some care should be taken. @@ -203,7 +203,7 @@ \section{Looking Up R Objects From Ruby} \begin{Verbatim} irb> r.foo -RException: Error in get(x, envir, mode, inherits) : +RException: Error in get(x, envir, mode, inherits) : variable "foo" was not found from /ruby/site_ruby/1.8/rsruby.rb:351:in `lcall' @@ -216,7 +216,7 @@ \section{Looking Up R Objects From Ruby} => 42 \end{Verbatim} -In the first case the R object |foo| is requested by RSRuby and an |RException| thrown when it is not found. After calling |assign| the |foo| variable exists in R and so can be found by RSRuby. +In the first case the R object |foo| is requested by RSRuby and an |RException| thrown when it is not found. After calling |assign| the |foo| variable exists in R and so can be found by RSRuby. Note that when a method is called on the R interpreter with out any arguments, a Ruby object representing the R object of the same name is returned. However, when called with arguments, the object requested is assumed to be an RObj (or subclass thereof) and is called with the arguments given. The conversion of the arguments from Ruby to R is covered in Chapter \ref{conversion_system} and the various calling semantics in section \ref{calling_R_functions}. @@ -493,7 +493,7 @@ \subsection{Enhanced RObj} => 4 \end{Verbatim} -To test the returned class we use the R |t.test| function, which returns an R list. Note the string representation of the returned object which matches the string form given by R. +To test the returned class we use the R |t.test| function, which returns an R list. Note the string representation of the returned object which matches the string form given by R. \begin{Verbatim} irb> e = r.t_test([1,2,3,4,5,6]) @@ -557,7 +557,7 @@ \subsection{DataFrames} \chapter{Input/Output} -RPy provides a number of utility functions +RPy provides a number of utility functions \chapter{Known Issues and To Do} @@ -585,13 +585,13 @@ \chapter{GNU Free Documentation License} Copyright \copyright 2000,2001,2002 Free Software Foundation, Inc. - + \bigskip - + 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - + \bigskip - + Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. \end{center} @@ -701,7 +701,7 @@ \chapter{GNU Free Documentation License} title either is precisely XYZ or contains XYZ in parentheses following text that translates XYZ in another language. (Here XYZ stands for a specific section name mentioned below, such as \textbf{"Acknowledgements"}, -\textbf{"Dedications"}, \textbf{"Endorsements"}, or \textbf{"History"}.) +\textbf{"Dedications"}, \textbf{"Endorsements"}, or \textbf{"History"}.) To \textbf{"Preserve the Title"} of such a section when you modify the Document means that it remains a section "Entitled XYZ" according to this definition. @@ -788,43 +788,43 @@ \chapter{GNU Free Documentation License} of it. In addition, you must do these things in the Modified Version: \begin{itemize} -\item[A.] +\item[A.] Use in the Title Page (and on the covers, if any) a title distinct from that of the Document, and from those of previous versions (which should, if there were any, be listed in the History section of the Document). You may use the same title as a previous version if the original publisher of that version gives permission. - + \item[B.] List on the Title Page, as authors, one or more persons or entities responsible for authorship of the modifications in the Modified Version, together with at least five of the principal authors of the Document (all of its principal authors, if it has fewer than five), unless they release you from this requirement. - + \item[C.] State on the Title page the name of the publisher of the Modified Version, as the publisher. - + \item[D.] Preserve all the copyright notices of the Document. - + \item[E.] Add an appropriate copyright notice for your modifications adjacent to the other copyright notices. - + \item[F.] Include, immediately after the copyright notices, a license notice giving the public permission to use the Modified Version under the terms of this License, in the form shown in the Addendum below. - + \item[G.] Preserve in that license notice the full lists of Invariant Sections and required Cover Texts given in the Document's license notice. - + \item[H.] Include an unaltered copy of this License. - + \item[I.] Preserve the section Entitled "History", Preserve its Title, and add to it an item stating at least the title, year, new authors, and @@ -833,7 +833,7 @@ \chapter{GNU Free Documentation License} stating the title, year, authors, and publisher of the Document as given on its Title Page, then add an item describing the Modified Version as stated in the previous sentence. - + \item[J.] Preserve the network location, if any, given in the Document for public access to a Transparent copy of the Document, and likewise @@ -842,26 +842,26 @@ \chapter{GNU Free Documentation License} You may omit a network location for a work that was published at least four years before the Document itself, or if the original publisher of the version it refers to gives permission. - + \item[K.] For any section Entitled "Acknowledgements" or "Dedications", Preserve the Title of the section, and preserve in the section all the substance and tone of each of the contributor acknowledgements and/or dedications given therein. - + \item[L.] Preserve all the Invariant Sections of the Document, unaltered in their text and in their titles. Section numbers or the equivalent are not considered part of the section titles. - + \item[M.] Delete any section Entitled "Endorsements". Such a section may not be included in the Modified Version. - + \item[N.] Do not retitle any existing section to be Entitled "Endorsements" or to conflict in title with any Invariant Section. - + \item[O.] Preserve any Warranty Disclaimers. \end{itemize} diff --git a/setup.rb b/setup.rb index 424a5f3..9f0c826 100644 --- a/setup.rb +++ b/setup.rb @@ -659,7 +659,7 @@ def command(*args) def ruby(*args) command config('rubyprog'), *args end - + def make(task = nil) command(*[config('makeprog'), task].compact) end @@ -722,7 +722,7 @@ def srcexist?(path) def srcdirectory?(path) File.dir?(srcfile(path)) end - + def srcfile?(path) File.file?(srcfile(path)) end @@ -826,7 +826,7 @@ def invoke __send__ "exec_#{task}" end end - + def run_metaconfigs @config.load_script "#{@ardir}/metaconfig" end @@ -1404,7 +1404,7 @@ def mapdir(ents) end # picked up many entries from cvs-1.11.1/src/ignore.c - JUNK_FILES = %w( + JUNK_FILES = %w( core RCSLOG tags TAGS .make.state .nse_depinfo #* .#* cvslog.* ,* .del-* *.olb *~ *.old *.bak *.BAK *.orig *.rej _$* *$ diff --git a/test/server.rb b/test/server.rb index c027ad5..204e819 100644 --- a/test/server.rb +++ b/test/server.rb @@ -4,7 +4,7 @@ class RSRuby include DRb::DRbUndumped end - + puts "starting..." DRb.start_service("druby://:7779", RSRuby) diff --git a/test/tc_boolean.rb b/test/tc_boolean.rb index c4b5c7e..8cf70ed 100644 --- a/test/tc_boolean.rb +++ b/test/tc_boolean.rb @@ -10,12 +10,12 @@ def setup end def test_true - assert_block "r.TRUE not working" do - (@r.typeof(@r.FALSE) == 'logical' and + assert_block "r.TRUE not working" do + (@r.typeof(@r.FALSE) == 'logical' and @r.as_logical(@r.TRUE)) end end - + def test_false assert_block "r.FALSE not working" do (@r.typeof(@r.FALSE) == 'logical' and not diff --git a/test/tc_cleanup.rb b/test/tc_cleanup.rb index 4bd681c..9101e01 100644 --- a/test/tc_cleanup.rb +++ b/test/tc_cleanup.rb @@ -1,6 +1,6 @@ require 'test/unit' require 'rsruby' - + class TestCleanup < Test::Unit::TestCase def setup @@ -11,12 +11,12 @@ def test_shutdown #@r.eval_R("shutdown_test=10") #@r.shutdown #assert_raise(RException){ @r.eval_R("shutdown_test") } - end - + end + def test_crash #Signal.trap('BUS','EXIT') #Signal.trap('BUS',proc{ puts 'hi there'; exit!}) - #@r.crash + #@r.crash end end diff --git a/test/tc_drb.rb b/test/tc_drb.rb index 74f1984..dec934b 100644 --- a/test/tc_drb.rb +++ b/test/tc_drb.rb @@ -6,7 +6,7 @@ class TestDrb < Test::Unit::TestCase def setup @r = RSRuby.instance end - + def test_me assert_equal 2, @r.eval_R("1+1") assert_equal 2, @r.eval_R("1+1") @@ -18,11 +18,11 @@ def test_me assert_equal 2, @r.eval_R("1+1") assert_equal 2, @r.eval_R("1+1") end - + def test_me_some_more assert_equal 5, @r.eval_R("2+3") end - + def test_me_once_again assert_equal 4, @r.eval_R("2+2") end diff --git a/test/tc_eval.rb b/test/tc_eval.rb index 6eb8c37..e96a2f4 100644 --- a/test/tc_eval.rb +++ b/test/tc_eval.rb @@ -15,7 +15,7 @@ def test_eval_R assert_equal(@r.eval_R("sum(1.5,2.5,3.5)"),7.5) assert_equal(@r.eval_R("eval('R')"),"R") assert_equal(@r.eval_R("is(1,'numeric')"),true) - assert_equal(@r.eval_R("is(1,'madeup')"),false) + assert_equal(@r.eval_R("is(1,'madeup')"),false) end end diff --git a/test/tc_extensions.rb b/test/tc_extensions.rb index b15640c..53161d3 100644 --- a/test/tc_extensions.rb +++ b/test/tc_extensions.rb @@ -3,9 +3,9 @@ class TestNewCases < Test::Unit::TestCase @@test_dir = File.expand_path File.dirname(__FILE__) - + def test_erobj - + require 'rsruby/erobj' r = RSRuby.instance r.proc_table[lambda{|x| true}] = lambda{|x| ERObj.new(x)} @@ -26,7 +26,7 @@ def test_dataframe RSRuby.set_default_mode(RSRuby::CLASS_CONVERSION) table = r.read_table(@@test_dir+"/table.txt",:header=>true) assert_instance_of(DataFrame,table) - + assert_equal(['A','B','C','D'],table.columns) assert_equal([1,2,3],table.rows) diff --git a/test/tc_io.rb b/test/tc_io.rb index 73e4a8f..6b6472d 100644 --- a/test/tc_io.rb +++ b/test/tc_io.rb @@ -41,14 +41,14 @@ def test_io_showfiles @r.help() assert out == ['foo'] end - + def test_io_stdout_exception #TODO - I can't understand this test in Rpy end def test_io_stdin_exception #TODO - I can't understand this test in Rpy - end + end def test_io_stderr_exception #TODO - I can't understand this test in Rpy diff --git a/test/tc_library.rb b/test/tc_library.rb index 48dcf9d..b0fb83f 100644 --- a/test/tc_library.rb +++ b/test/tc_library.rb @@ -15,6 +15,6 @@ def test_library def test_library_fail #Test failure assert_raises(RException){@r.library("Missing")} - end + end end diff --git a/test/tc_modes.rb b/test/tc_modes.rb index 0e128c0..9f77f87 100644 --- a/test/tc_modes.rb +++ b/test/tc_modes.rb @@ -36,7 +36,7 @@ def test_to_ruby_default_arg RSRuby.set_default_mode(RSRuby::BASIC_CONVERSION) assert_equal(sequence.to_ruby, [1,2,3]) - + RSRuby.set_default_mode(RSRuby::VECTOR_CONVERSION) assert_equal(sequence.to_ruby, [1,2,3]) @@ -75,7 +75,7 @@ def test_no_default_mode @r.seq.autoconvert(RSRuby::BASIC_CONVERSION) assert_equal(@r.array(1,3).class, @r.array.class) - + assert_equal(@r.seq(1,3), [1,2,3]) @r.class_table['htest'] = lambda{|x| 5} assert_equal(@r.t_test([1,2,3]), 5) @@ -98,7 +98,7 @@ def test_individual_conversions assert_equal(@r.c(4), 4) assert_equal(@r.seq(1,3), [1,2,3]) assert_equal(@r.min(1,3), [1]) - + RSRuby.set_default_mode(RSRuby::BASIC_CONVERSION) assert_equal(@r.c.autoconvert, RSRuby::BASIC_CONVERSION) assert_equal(@r.seq.autoconvert, RSRuby::PROC_CONVERSION) @@ -118,7 +118,7 @@ def test_individual_conversions end def test_vector_conversion - + RSRuby.set_default_mode(RSRuby::VECTOR_CONVERSION) assert_equal(@r.c(true), [true]) @@ -127,7 +127,7 @@ def test_vector_conversion assert_equal(@r.c(1,'A',2), ['1','A','2']) assert_equal(@r.c(:a => 1, :b => 'A', :c => 2), {'a' => '1', 'b' => 'A', 'c' => '2'}) - assert_equal(@r.list(:a => 1, :b => 'A', :c => 2), + assert_equal(@r.list(:a => 1, :b => 'A', :c => 2), {'a' => [1], 'b' => ['A'], 'c' => [2]}) assert_equal(@r.eval_R("x~y").class, RObj) end @@ -141,16 +141,16 @@ def test_basic_conversion assert_equal(@r.c(1,'A',2), ['1','A','2']) assert_equal(@r.c(:a => 1, :b => 'A', :c => 2), {'a' => '1', 'b' => 'A', 'c' => '2'}) - assert_equal(@r.list(:a => 1, :b => 'A', :c => 2), + assert_equal(@r.list(:a => 1, :b => 'A', :c => 2), {'a' => 1, 'b' => 'A', 'c' => 2}) assert_equal(@r.eval_R("x~y").class, RObj) - + end def test_class_table @r.class_table['htest'] = lambda{|x| 'htest'} - @r.class_table['data.frame'] = lambda{|x| + @r.class_table['data.frame'] = lambda{|x| if @r['[['].call(x,1).length > 2 return 5 else @@ -180,10 +180,10 @@ def test_multiple_class_table @r.class_table.delete(['bar','foo']) assert_equal(g.to_ruby, 'bar') - + @r.class_table.delete('bar') assert_equal(g.to_ruby, 'foo') - + end def test_proc_table @@ -216,7 +216,7 @@ def test_proc_convert return "Cannot return 'foo'" if x == 'foo' return x } - + r.proc_table[check_str] = f RSRuby.set_default_mode(RSRuby::PROC_CONVERSION) @@ -230,12 +230,12 @@ def test_proc_convert def test_restore_mode_after_exception_in_proc r = RSRuby.instance - + check_str = lambda{|x| RSRuby.instance.is_character(x)} f = lambda{|x| x.reverse } - + r.proc_table[check_str] = f RSRuby.set_default_mode(RSRuby::PROC_CONVERSION) diff --git a/test/tc_to_r.rb b/test/tc_to_r.rb index 27d2f72..b36d1cf 100644 --- a/test/tc_to_r.rb +++ b/test/tc_to_r.rb @@ -87,23 +87,23 @@ def test_char_to_char end def test_hash_to_named_vector - @r.c.autoconvert(RSRuby::NO_CONVERSION) + @r.c.autoconvert(RSRuby::NO_CONVERSION) assert_equal(@r.typeof(@r.c(:foo => 5, :bar => 7)),'integer') - + assert(@r.attributes(@r.c(:foo => 5, :bar => 7))['names'].include?('foo')) assert(@r.attributes(@r.c(:foo => 5, :bar => 7))['names'].include?('bar')) #TODO - these fail because of the different calling semantics in #RSRuby - #@r.c.autoconvert(RSRuby::BASIC_CONVERSION) + #@r.c.autoconvert(RSRuby::BASIC_CONVERSION) #assert_equal(@r.typeof(@r.c(:foo => 5, :bar => 7)),'integer') #assert(@r.attributes(@r.c(:foo => 5, :bar => 7))['names'].include?('foo')) - #assert(@r.attributes(@r.c(:foo => 5, :bar => 7))['names'].include?('bar')) + #assert(@r.attributes(@r.c(:foo => 5, :bar => 7))['names'].include?('bar')) end def test_array_to_vector - @r.c.autoconvert(RSRuby::NO_CONVERSION) + @r.c.autoconvert(RSRuby::NO_CONVERSION) assert_equal(@r.length(@r.c(1,2,3,4)),4) - @r.c.autoconvert(RSRuby::BASIC_CONVERSION) + @r.c.autoconvert(RSRuby::BASIC_CONVERSION) assert_equal(@r.length(@r.c(1,2,3,4)),4) end diff --git a/test/tc_to_ruby.rb b/test/tc_to_ruby.rb index 6b015a7..1e1119c 100644 --- a/test/tc_to_ruby.rb +++ b/test/tc_to_ruby.rb @@ -3,7 +3,7 @@ class TestToRuby < Test::Unit::TestCase @@test_dir = File.expand_path File.dirname(__FILE__) - + def setup @r = RSRuby.instance RSRuby.set_default_mode(RSRuby::NO_DEFAULT) @@ -49,8 +49,8 @@ def test_factor_NA def test_NA_list - #TODO - RPy has commented out these tests as well. - #The conversion between NA/NaN and Ruby seems a little confused + #TODO - RPy has commented out these tests as well. + #The conversion between NA/NaN and Ruby seems a little confused #at the moment xi = [1,2,@r.NA,@r.NaN,4] @@ -65,21 +65,21 @@ def test_NA_list #assert_equal(@r.as_numeric(xi) , [1.01,2.01,@r.NA,@r.NaN,4.01]) assert_equal(@r.as_integer(xd) , [1,2,@r.NA,@r.NA,4]) assert_equal(@r.factor(xd) , ['1.01','2.02','NA','NaN','4.04']) - assert_equal(@r.is_na(xd) , [false, false, true, true, false]) + assert_equal(@r.is_na(xd) , [false, false, true, true, false]) end #TODO - table.txt????????? def test_dataframe_to_list @r.read_table.autoconvert(RSRuby::BASIC_CONVERSION) - assert_equal(@r.read_table(@@test_dir+"/table.txt", {:header => 1}), + assert_equal(@r.read_table(@@test_dir+"/table.txt", {:header => 1}), { - 'A' => ['X1','X2','X3'], - 'C' => [5,8,2], + 'A' => ['X1','X2','X3'], + 'C' => [5,8,2], 'B' => [4.0,7.0,6.0], 'D' => ['6','9','Foo'] }) end - + def test_logical_to_boolean assert_equal(@r.TRUE, true) assert_equal(@r.T, true) @@ -147,7 +147,7 @@ def test_vector_coercion assert_equal(@r.typeof(@r.c(1,2,3)), 'integer') assert_equal(@r.typeof(@r.c(1,2.0,3)), 'double') assert_equal(@r.typeof(@r.c(1,Complex(2,3),3)), 'complex') - assert_equal(@r.typeof(@r.c(1,'foo',3)), 'character') + assert_equal(@r.typeof(@r.c(1,'foo',3)), 'character') end end diff --git a/test/testsegfault.rb b/test/testsegfault.rb index c180efe..2a7af6d 100644 --- a/test/testsegfault.rb +++ b/test/testsegfault.rb @@ -5,7 +5,7 @@ RSRuby.set_default_mode(RSRuby::NO_DEFAULT) -r.c.autoconvert(RSRuby::NO_CONVERSION) +r.c.autoconvert(RSRuby::NO_CONVERSION) puts r.typeof(r.c(:foo => 5, :bar => 7)) puts r.attributes(r.c(:foo => 5, :bar => 7))['names'].include?('foo') puts r.attributes(r.c(:foo => 5, :bar => 7))['names'].include?('bar')