So, you have a data set collected in E-Prime and you want to export for processing in another tool suite? Since it takes half a dozen mouse clicks per file, you can only image how un-fun this gets once the data set grows to dozens or hundreds of files.
There are three methods for exporting a data set of edat2 files that I know of:
1) Manually click your way through the whole data set and export each individually.
2) Use E-Merge to merge the all the files into one huge file... then export it in one step... then figure out how to process it (either split it back into individual participant chunks or do a population study on the whole lot)
3) Use the below script to get it all done automagically in one mouseclick.
My problem is that each year I have dozens of E-Prime data sets to handle. This has resulted in needing to process literally hundreds of edat2 files every year. I usually teach the student how to do the manual export method but that was still prone to human error and often resulted in me having to go and find a file that had been miss-named or skipped in the process. More time and effort spent. This is a repetative problem with no variability... there had to be an automated solution.
So after appropriate googling around and some futile autohotkey hacking, I contacted PST help and found a helpful customer support person. After explaining my need and establishing that the first two solutions above were not suitable for my problem, the support person produced some documentation for a simple command line interface to E-DataAid. This provided me with a scriptable interface that I needed. Add a little Perl hacking and tada.... solution.
Find below my solution and some notes.
The Solution for Exporting edat2 files to text files
For this solution I used perl as my scripting language of choice. I recomend the ActiveState ActivePerl.To use this file you will need perl and E-Prime 2 installed on the computer. Then simply copy this script into a text file and name it something useful, like "DumpEdatToText.pl" and save it in the directory with the edat2 files.
The doubleclick the perl script to run it. It should export each edat2 file to a tab-delimited text file named with the participant id and session id. For example "p1s1.csv" (Note: while this is not strictly speaking a CSV file, the file extension makes it easy to import into Excel for my purposes)
Following is my perl script:
#get all the edat2 files in the current directory
my @files = glob("*.edat2");
#process file each individually
foreach my $file(@files){
print $file . " being processed\n";
#get the participant ID and session ID from the file name
my $p = "partID not found";
#my $p = substr $file, index($file, "-"), 1;
if ($file =~ /\-([^-]+)\-/)
{
$p = $1;
}
my $s = "SessionID not found";
if ($file =~ /\-([^-]+)\./)
{
$s = $1;
}
my $outfileName = "p" . $p . "s" . $s . ".csv";
#process the command file
my $theCommandFileName = "cmdFile.txt";
unless( open cmdFile, '>:crlf', $theCommandFileName){
die "\nUnable to open $theCommandFileName\n";
}
print cmdFile ("Inheritance=true" . "\n");
print cmdFile ("InFile=" . $file . "\n");
print cmdFile ("OutFile=" . $outfileName . "\n");
print cmdFile ("ColFlags=0" . "\n");
print cmdFile ("ColNames=1" . "\n");
print cmdFile ("Comments=0" . "\n");
print cmdFile ("BegCommentLine=" . "\n");
print cmdFile ("EndCommentLine=" . "\n");
print cmdFile ("DataSeparator= " . "\n"); #<tab character
print cmdFile ("VarSeparator= " . "\n"); #<tab character
print cmdFile ("BegDataLine=" . "\n");
print cmdFile ("EndDataLine=" . "\n");
print cmdFile ("MissingData=" . "\n");
print cmdFile ("Unicode=1" . "\n");
close cmdFile;
#pass the command file to E-DataAid for export
system('"C:\Program Files (x86)\PST\E-Prime 2.0\Program\E-DataAid.exe" /e /f cmdFile.txt');
}
End Perl Script
Notes
Error Messages from E-DataAidError 1
No Output and no error message generated when running the following command
"C:\Program Files (x86)\PST\E-Prime 2.0\Program\E-DataAid.exe" /e exampleB.txt
Solution – forgot to include the /f flag on command line. Now works.
"C:\Program Files (x86)\PST\E-Prime 2.0\Program\E-DataAid.exe" /e /f exampleB.txt
The missing flag should generate an error message.
Error 2
Message: “Error Reading Unicode from command file”
Solution – Added “Unicode=1” to end of command file. Guessed that it’s a flag field. Seems to work.
Error 3
Message: “Error Reading E-Prime data file: D:\TestDumper\test.edat2 file”
Solution – Had the full path to the file in the command file. Replaced with a relative path and the command worked.
InFile=D:\TestDumper\test.edat2 <-Failed
InFile=nBackVerbal-1-1.edat2 <- Worked
Error 4
Leaving the “InFile=” field empty will crash E-DataAid
E-DataAid should correctly handle and report the missing field.
Error 5
Leaving the “OutFile=” field empty will generate a spurious error message. “Error exporting to text file: .”
E-DataAid should detect the missing field and correctly report that there is no output file name supplied.
Error 6
Absolute file path in the “InFile=” field to edat2 file cause failure.
This may be due to assuming that the file is in the current working directory????
Solution- Use a relative path or work in the same directory.
No comments:
Post a Comment