From f9f51b6ab4c7280dd521da675353252d7b078984 Mon Sep 17 00:00:00 2001
From: Benjamin Auder <benjamin.auder@somewhere>
Date: Wed, 11 Jan 2017 01:58:48 +0100
Subject: [PATCH] improve wrapper.R to handle files too

---
 code/stage1/wrapper.R | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/code/stage1/wrapper.R b/code/stage1/wrapper.R
index e1fa30e..524fc90 100644
--- a/code/stage1/wrapper.R
+++ b/code/stage1/wrapper.R
@@ -5,9 +5,16 @@ ppam_exe = function(path=".", np=parallel::detectCores(), data=NULL, args="DontL
 	#if data provided (as data.frame or matrix...): binarize it, and add it as first argument
 	if (!is.null(data))
 	{
-		write.csv(data, "/tmp/data_csv")
-		system(paste(path,"/ppam.exe serialize /tmp/data_csv /tmp/data_bin 0 0",sep=""))
-		command_line = paste(command_line," ","/tmp/data_bin",sep="")
+		if (!is.character(data))
+		{
+			#assuming matrix or data.frame, WITH row names (identifiers; could be line number...)
+			write.csv(data, "/tmp/data_csv", row.names=TRUE, col.names=FALSE)
+			system(paste(path,"/ppam.exe serialize /tmp/data_csv /tmp/data_bin 0 0",sep=""))
+		} else
+		{
+			system(paste(path,"/ppam.exe serialize ",data," /tmp/data_bin 0 0",sep=""))
+		}
+		command_line = paste(command_line," /tmp/data_bin",sep="")
 	}
 
 	command_line = paste(command_line," ",args,sep="")
-- 
2.44.0