module PubliSci::Writers::Dataframe

Public Instance Methods

create_dataframe(name, connection, rows, vectors) click to toggle source
# File lib/publisci/writers/dataframe.rb, line 21
def create_dataframe(name, connection, rows, vectors)
  connection.assign('rows', rows)
  vectors.map{ |k,v|
    connection.assign(k,v)
  }
  connection.eval(framestring(name,vectors))
  connection.eval("row.names(#{name}) <- rows")
  connection.eval(name)
end
framestring(name,vectors) click to toggle source
# File lib/publisci/writers/dataframe.rb, line 5
def framestring(name,vectors)
  framestr = "#{name} = data.frame("
  vectors.map{ |k,v| framestr << k + '=' + k +','}
  framestr[-1] = ')'
  framestr
end
get_rownames(variable, helper, repo) click to toggle source
# File lib/publisci/writers/dataframe.rb, line 35
def get_rownames(variable, helper, repo)
  rows = helper.get_ary(helper.execute(helper.row_names(variable), repo)).flatten
end
get_vectors(variable_name, helper, repo) click to toggle source
# File lib/publisci/writers/dataframe.rb, line 12
def get_vectors(variable_name, helper, repo)
  column_names = helper.get_ary(helper.execute(helper.property_names(variable_name), repo)).flatten.map{|n| n.gsub(' Component','')}
  vectors = {}
  column_names.map{|n|
    vectors[n] = helper.get_ary(helper.execute(helper.property_values(variable_name,n),repo),'to_f').flatten unless n == "refRow"
  }
  vectors
end
save_workspace(connection, loc) click to toggle source
# File lib/publisci/writers/dataframe.rb, line 31
def save_workspace(connection, loc)
  connection.eval "save.image(#{loc})"
end