Module: PubliSci::Writers::Dataframe

Included in:
Builder
Defined in:
lib/publisci/writers/dataframe.rb

Instance Method Summary collapse

Instance Method Details

#create_dataframe(name, connection, rows, vectors) ⇒ Object


21
22
23
24
25
26
27
28
29
# 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) ⇒ Object


5
6
7
8
9
10
# 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) ⇒ Object


35
36
37
# 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) ⇒ Object


12
13
14
15
16
17
18
19
# 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) ⇒ Object


31
32
33
# File 'lib/publisci/writers/dataframe.rb', line 31

def save_workspace(connection, loc)
  connection.eval "save.image(#{loc})"
end