Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
R to Divvy exporter. Thanks to Tom Wisdom for contributing the base c…
…ode.
- Loading branch information
Joshua M. Lewis
committed
Feb 9, 2012
1 parent
e2eb5a6
commit 00bee92
Showing
1 changed file
with
20 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#### R data.frame to Divvy binary file export written by Tom Wisdom | ||
#### & Josh Lewis 2012 | ||
rtodivvy <- function(inputData, name) { | ||
# Data must be dense and real-valued. Check for this in the future. | ||
# Dimensions are in columns & samples are in rows unlike the Matlab | ||
# exporter but as per R convention. | ||
dimensions <- length(inputData[1,]) | ||
samples <- length(inputData[,1]) | ||
# Concatenate rows (after converting data.frame to matrix and values to double) | ||
inputData_vec <- as.double(t(as.matrix(inputData))) | ||
|
||
filename <- paste(name, ".bin", sep="") | ||
fid <- file(description = filename, open = "wb") | ||
|
||
writeBin(samples, fid, size=4) | ||
writeBin(dimensions, fid, size=4) | ||
writeBin(inputData_vec, fid, size=4) | ||
|
||
close(fid) | ||
} |