[chronojump] Fixing R paths windows... Rscript



commit 3d2a2b650551f1670f47d164e269195c31304149
Author: Xavier de Blas <xaviblas gmail com>
Date:   Fri Feb 1 00:54:51 2013 +0100

    Fixing R paths windows... Rscript

 encoder/graph.R                   |    2 +-
 encoder/pyserial_pyper_windows.py |    6 +++++-
 src/util.cs                       |   30 +++++++++++++++++++++++++-----
 win32/deps/bin/Rscript.exe        |  Bin 0 -> 31232 bytes
 4 files changed, 31 insertions(+), 7 deletions(-)
---
diff --git a/encoder/graph.R b/encoder/graph.R
index 83b879f..45e1923 100644
--- a/encoder/graph.R
+++ b/encoder/graph.R
@@ -47,7 +47,7 @@ getOptionsFromFile <- function(optionsFile) {
 
 
 args <- commandArgs(TRUE)
-eval(parse(text=args[[1]])) #optionsFile is assigned in R CMD BATCH:  '--args optionsFile="/tmp/Roptions.txt"' 
+optionsFile =args[1]
 
 print(optionsFile)
 
diff --git a/encoder/pyserial_pyper_windows.py b/encoder/pyserial_pyper_windows.py
index b660740..431e47c 100644
--- a/encoder/pyserial_pyper_windows.py
+++ b/encoder/pyserial_pyper_windows.py
@@ -63,6 +63,7 @@ peakPowerHigherCondition = int(sys.argv[17])
 peakPowerLowerCondition = int(sys.argv[18])
 mainVariable = sys.argv[19]
 w_serial_port = sys.argv[20]
+r_path = sys.argv[21]
 
 delete_initial_time = 20			#delete first records because there's encoder bug
 #w_baudrate = 9600                           # Setting the baudrate of Chronopic(9600)
@@ -416,6 +417,7 @@ def printHeader(option):
 
 #try:
 if __name__ == '__main__':
+	print(sys.path[0])
 	print("Please, wait...\n")
 	# initialize pygame.mixer module
 	# if these setting do not work with your audio system
@@ -425,9 +427,11 @@ if __name__ == '__main__':
 	except pygame.error, exc:
 		print >>sys.stderr, "Could not initialize sound system: %s" % exc
 	
+	
+	
 	#print "connecting with R"
 	#myR = R()
-	myR = R(RCMD="C:\\Program Files\\R\\R-2.15.2\\bin\\R")
+	myR = R(RCMD=r_path)
 
 	myR.run('library("EMD")') #needed on reducing curve by speed (extrema)
 	myR.assign('mass',mass)
diff --git a/src/util.cs b/src/util.cs
index 8a4a4df..ad1cf50 100644
--- a/src/util.cs
+++ b/src/util.cs
@@ -1078,9 +1078,15 @@ public class Util
 		string outputFileCheck = "";
 		
 
+		/*
+		on Windows (py2exe) we execute a exe with the py file that contains python
+		on linux we execute python and call to the py file
+		also on windows we need the full path to find R
+		*/
 		if (IsWindows()) {
 			pBin=getEncoderScriptCapture();
-			pinfo.Arguments = title + " " + es.OutputData1 + " " + es.Ep.ToString1() + " " + port;
+			pinfo.Arguments = title + " " + es.OutputData1 + " " + es.Ep.ToString1() + " " + port 
+				+ " " + System.IO.Path.Combine(GetPrefixDir(), "bin" + Path.DirectorySeparatorChar + "R");
 		}
 		else {
 			pBin="python";
@@ -1121,11 +1127,17 @@ public class Util
 
 		string outputFileCheck = "";
 			
-		//pBin="Rscript";
-		pBin="R";
-		if (IsWindows())
+		pBin="Rscript";
+		//pBin="R";
+		if (IsWindows()) {
 			pBin=System.IO.Path.Combine(GetPrefixDir(), "bin" + Path.DirectorySeparatorChar + "R.exe");
 
+			//On win32 R understands backlash as an escape character and 
+			//a file path uses Unix-like path separator '/'		
+			es.OutputGraph = es.OutputGraph.Replace("\\","/");
+			es.OutputData1 = es.OutputData1.Replace("\\","/");
+			es.OutputData2 = es.OutputData2.Replace("\\","/");
+		}
 		
 		//--- way A. passing options to a file
 		string scriptOptions = es.InputData + "\n" + 
@@ -1137,11 +1149,19 @@ public class Util
 		writer.Write(scriptOptions);
 		writer.Flush();
 		((IDisposable)writer).Dispose();
+		
+		if (IsWindows()) {
+			//On win32 R understands backlash as an escape character and 
+			//a file path uses Unix-like path separator '/'		
+			optionsFile = optionsFile.Replace("\\","/");
+		}
 
-		//pinfo.Arguments = script + " " + optionsFile;
+		pinfo.Arguments = getEncoderScriptGraph() + " " + optionsFile;
+		/*
 		pinfo.Arguments = "CMD BATCH --no-save '--args optionsFile=\"" + optionsFile + "\"' \"" + 
 			getEncoderScriptGraph() + "\" \"" + 
 			Path.GetTempPath() + "error.txt\"";
+			*/
 		
 		//--- way B. put options as arguments
 		/*
diff --git a/win32/deps/bin/Rscript.exe b/win32/deps/bin/Rscript.exe
new file mode 100644
index 0000000..0d37a50
Binary files /dev/null and b/win32/deps/bin/Rscript.exe differ



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]