Add Codes to a Column

Add Codes to a Column

Adding codes to a column is a straightforward scriptable task. The Datavyu API provides the add_code() method for adding codes.

add_code() takes the names of the Datavyu codes you are adding as its parameters. This example adds a code called unit to the “trial” Datavyu column in the sample data. The unit code might represent the unit of measure used during an experiment.

  1. Start by setting up the script and assigning the Datavyu column “trial” to a variable using getColumn(). You can call your variable whatever you want to. We’re calling it trial in this example:

    require 'Datavyu_API.rb'
    begin
       # Retrieve "trial" data from Datavyu spreadsheet and assign it
       # to a new Ruby variable
       trial = getColumn("trial")
    
  2. Add the unit code to trial using add_code():

    require 'Datavyu_API.rb'
    begin
       trial = getColumn("trial")
    
       # Add the "unit" code to the trial variable
       trial.add_code("unit")
    
  3. Write the changes back to the Datavyu spreadsheet using setColumn() and end the script:

    require 'Datavyu_API.rb'
    begin
       trial = getColumn("trial")
       trial.add_code("unit")
    
       # Write the changes back to the Datavyu spreadsheet
       setColumn(trial)
    end