Module: R

Defined in:
lib/R_interface/rlist.rb,
lib/R_interface/r.rb,
lib/R_interface/rpkg.rb,
lib/R_interface/rmatrix.rb,
lib/R_interface/robject.rb,
lib/R_interface/rsymbol.rb,
lib/R_interface/rvector.rb,
lib/R_interface/rclosure.rb,
lib/R_interface/rsupport.rb,
lib/R_interface/r_methods.rb,
lib/R_interface/rlanguage.rb,
lib/R_interface/r_module_s.rb,
lib/R_interface/rdata_frame.rb,
lib/R_interface/rexpression.rb,
lib/R_interface/renvironment.rb,
lib/R_interface/ruby_callback.rb,
lib/R_interface/rsupport_scope.rb,
lib/R_interface/rindexed_object.rb,
lib/R_interface/ruby_extensions.rb,
lib/R_interface/runary_operators.rb,
lib/R_interface/rbinary_operators.rb,
lib/R_interface/rlogical_operators.rb,
lib/R_interface/rmd_indexed_object.rb

Overview

Copyright © 2018 Rodrigo Botafogo. All Rights Reserved. Permission to use, copy, modify, and distribute this software and its documentation, without fee and without a signed licensing agreement, is hereby granted, provided that the above copyright notice, this paragraph and the following two paragraphs appear in all copies, modifications, and distributions.

IN NO EVENT SHALL RODRIGO BOTAFOGO BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF RODRIGO BOTAFOGO HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

RODRIGO BOTAFOGO SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED “AS IS”. RODRIGO BOTAFOGO HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.

Author:

  • Rodrigo Botafogo

Defined Under Namespace

Modules: BinaryOperators, CallBinOp, ExecBinOp, ExecUniOp, ExpBinOp, ExpUniOp, IndexedObject, LogicalOperators, MDIndexedObject, S, Scope, Support, UnaryOperators Classes: Closure, DataFrame, Environment, Language, List, Matrix, NotAvailable, Object, Package, RExpression, RSymbol, RubyCallback, Vector

Constant Summary collapse

RCONSTANTS =
["LETTERS", "letters", "month.abb", "month.name", "pi"]
NA =
NotAvailable.new(@na)

Class Method Summary collapse

Class Method Details

.const_missing(name) ⇒ Object





57
58
59
# File 'lib/R_interface/rpkg.rb', line 57

def self.const_missing(name)
  R::Package[name.to_s.downcase]
end

.empty_symbolObject

@@empty_symbol = Polyglot.eval(“R”, <<-R)

  __missing_arg = quote(f(,0));
  __missing_arg[[2]]
R

def self.empty_symbol
  @@empty_symbol
end


43
44
45
# File 'lib/R_interface/rsupport.rb', line 43

def self.empty_symbol
  Polyglot.eval("R", "missing_arg()")
end

.install_and_loads(*libs) ⇒ Object





90
91
92
93
# File 'lib/R_interface/r.rb', line 90

def self.install_and_loads(*libs)
  R.install_rlibs(*libs)
  libs.each { |lib| R.require lib }
end

.install_rlibs(*libs) ⇒ Object


Checks to see if the given libs are installed in R and if not, install them install


Parameters:

  • libs (Array)

    Array of strings with the names of the libraries to check and



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/R_interface/r.rb', line 65

def self.install_rlibs(*libs)

  packages = R.c(*libs)

  new_packages = packages[!(packages._ :in, R.installed__packages[:all, "Package"])]
  
  if(new_packages.size > 0)
    
    # package 'data_table' cannot be installed by install.packages.  FastR implements
    # install.fastr.packages for installing 'data_table'
    if ((R.c('data.table')._ :in, new_packages) >> 0)
      new_packages = new_packages[!'data_table']
      R.install__fastr__packages('data_table')
    end
    
    puts "The following packages are missing and will be installed:\n #{new_packages}"
    R.install__packages(new_packages)
  end
  
end

.internal_eval(symbol, *args) ⇒ Object





55
56
57
# File 'lib/R_interface/r.rb', line 55

def self.internal_eval(symbol, *args)
  R::Support.process_missing(symbol, true, *args)
end

.method_missing(symbol, *args, &block) ⇒ Object


Executes a missing method. If a block is given, then the method needs to be executed in the scope of the block. @bug: Not ready yeat




40
41
42
43
44
45
46
47
48
49
# File 'lib/R_interface/r.rb', line 40

def self.method_missing(symbol, *args, &block)
  
  if (block_given?)
    val = R::Support.process_missing(symbol, false, *args)
    return R::Support.new_scope(symbol, val, *args, &block)
  end

  R::Support.process_missing(symbol, false, *args)

end