Announcing the new Datavyu v1.3.6 with enhanced features and transcription support!

Can scripts be used to perform batch operations on columns themselves (not just the codes within columns)? For example, if I want to rename the 3rd column in several spreadsheets, can this be accomplished with a script?

I found instructions in the user guide for renaming codes with an RColumn Class script, and it looks like this could be modified for a batch operation pretty easily. However, I have not found any information on using scripts to change column names. Does anyone have a script that accomplishes this or suggestions for an alternate approach?

asked 15 Jan '16, 16:46

Penina%20Backer's gravatar image

Penina Backer
accept rate: 0%

The simplest way to rename is to use the setVariable() function with a different name for the column. Then you could simply remove the column corresponding to the old name using deleteVariable(column_name). I'll attach example code below.

col = getVariable('trial') setVariable('task', col) deleteVariable('trial')

It looks like this method is not documented in the reference— we will add the proper documentation as soon as possible.

Let us know if you need help with making a batch script.

permanent link

answered 15 Jan '16, 17:00

Shohan%20Hasan's gravatar image

Shohan Hasan ♦♦
accept rate: 12%

Thanks so much Shohan. Can I please get help making this into a batch script?

In my current setup, I have a folder containing files from 2 different coders, 1 primary coder and 1 reliability coder. The reliability files have REL in the title and an REL prefix before column names. What I would optimally like the script to do is select REL files from the folder and rename the columns so that they no longer have the REL prefix. Does this sound feasible?

(21 Jan '16, 11:34) Penina Backer Penina%20Backer's gravatar image

Batching is a very common task and we've developed a sample script to run single-spreadsheet scripts on many files. For your specific case, let's just directly write a script to manipulate all the necessary Datavyu files.

Here is a reference to the Ruby documentation for additional information about core Ruby functions (separate from the Datavyu API) : Ruby 1.8.7 Documentation

The primary classes we will use here are: Dir, and File.

## Params
original_column_name = 'REL_blahblah' # replace with actual column names!
new_column_name = 'blahblah'
input_folder = File.expand_path('~/Desktop/DatavyuFiles') # Replace with actual folder path!
file_matcher = "*REL*.opf" # this will pick up any Datavyu files that have REL in the filename

## Body
require 'Datavyu_API.rb'

# Change to the input directory and get get a list of filenames matching our file_matcher
infiles = Dir.chdir(input_folder){ Dir.glob(file_matcher) }

# Loop over list of filenames
infiles.each do |file|
  filePath = File.join(input_folder, file) # Get the full path to the Datavyu files
  loadDB(filePath) # load the spreadsheet

  # Save the column as a new column with different name
  setVariable(new_column_name, getVariable(original_column_name))

  # Delete the column with the old name

  # Save the spreadsheet to file

In case you want to do more batching, here is a a sample script that allows you to run a script on a whole folder of Datavyu files: RunBatch.rb

Let us know if you have any more questions.

permanent link

answered 21 Jan '16, 15:19

Shohan%20Hasan's gravatar image

Shohan Hasan ♦♦
accept rate: 12%

edited 21 Jan '16, 15:20

When I run the sample script above, I get the following error message:

Running Script: Change Column Name.rb on project: BB007_4YA_cleanup_bx

WARNING: No column with name 'Rel_Cleanup_Behaviors' was found! NoMethodError: undefined method db_var' for nil:NilClass setVariable at file:/C:/Temp/DV/Datavyu-Windows-latest/datavyu-1.2/datavyu-1.2.exe!/Datavyu_API.rb:523 (root) at <script>:23 each at org/jruby/ (root) at <script>:18 (NoMethodError) undefined methoddb_var' for nil:NilClass

It looks like the script is running on whichever file is open in datavyu instead of running on the input folder. How can I fix this?

permanent link

answered 22 Jan '16, 11:42

Penina%20Backer's gravatar image

Penina Backer
accept rate: 0%


Yes, you are right. Could you please replace the line "loadDB(filepath)" with "$db, $proj = loadDB(filepath)"? This will update the current working database and project workspace with the ones from the loaded file.

(22 Jan '16, 17:42) Shohan Hasan ♦♦ Shohan%20Hasan's gravatar image
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:


question asked: 15 Jan '16, 16:46

question was seen: 6,830 times

last updated: 22 Jan '16, 17:42

Related questions

powered by OSQA