[GRASS-SVN] r68694 - grass-addons/grass7/vector/v.class.mlR

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Jun 15 08:18:08 PDT 2016


Author: mlennert
Date: 2016-06-15 08:18:08 -0700 (Wed, 15 Jun 2016)
New Revision: 68694

Modified:
   grass-addons/grass7/vector/v.class.mlR/v.class.mlR.html
   grass-addons/grass7/vector/v.class.mlR/v.class.mlR.py
Log:
v.class.mlR: allow user choice for field separator in input csv files


Modified: grass-addons/grass7/vector/v.class.mlR/v.class.mlR.html
===================================================================
--- grass-addons/grass7/vector/v.class.mlR/v.class.mlR.html	2016-06-15 01:22:11 UTC (rev 68693)
+++ grass-addons/grass7/vector/v.class.mlR/v.class.mlR.html	2016-06-15 15:18:08 UTC (rev 68694)
@@ -9,11 +9,11 @@
 and <em>training_map</em>, or as csv files (<em>segments_file</em> and
 <em>training file</em>, or a combination of both. Csv files have to be
 formatted in line with the default output of 
-<a href"v.db.select.html">v.db.select</a>, i.e. with a header and the
-pipe character as field separator.  Output can consist of either 
-additional columns in the vector input map of features, a text file 
-(<em>classification_results</em>) or reclassed raster maps 
-(<em>classified_map</em>).
+<a href"v.db.select.html">v.db.select</a>, i.e. with a header. The field
+separator can be set with the <em>separator</em> parameter.
+Output can consist of either additional columns in the vector input map 
+of features, a text file (<em>classification_results</em>) or reclassed 
+raster maps (<em>classified_map</em>).
 
 <p>The user has to provide the name of the column in the training data
 that contains the class values (<em>train_class_column</em>), the prefix

Modified: grass-addons/grass7/vector/v.class.mlR/v.class.mlR.py
===================================================================
--- grass-addons/grass7/vector/v.class.mlR/v.class.mlR.py	2016-06-15 01:22:11 UTC (rev 68693)
+++ grass-addons/grass7/vector/v.class.mlR/v.class.mlR.py	2016-06-15 15:18:08 UTC (rev 68694)
@@ -68,6 +68,10 @@
 #% required: no
 #% guisection: Text input
 #%end
+#%option G_OPT_F_SEP
+#% description: Field separator in input text files
+#% guisection: Text input
+#%end
 #%option G_OPT_R_INPUT
 #% key: raster_segments_map
 #% label: Raster map with segments
@@ -289,6 +293,7 @@
     folds = options['folds']
     partitions = options['partitions']
     tunelength = options['tunelength']
+    separator = gscript.separator(options['separator'])
 
     classification_results = None
     if options['classification_results']:
@@ -356,9 +361,9 @@
     r_file.write("\n")
     r_file.write('require(caret)')
     r_file.write("\n")
-    r_file.write('features <- read.csv("%s", sep="|", header=TRUE, row.names=1)' % feature_vars)
+    r_file.write('features <- read.csv("%s", sep="%s", header=TRUE, row.names=1)' % (feature_vars, separator))
     r_file.write("\n")
-    r_file.write('training <- read.csv("%s", sep="|", header=TRUE, row.names=1)' % training_vars)
+    r_file.write('training <- read.csv("%s", sep="%s", header=TRUE, row.names=1)' % (training_vars, separator))
     r_file.write("\n")
     r_file.write("training$%s <- as.factor(training$%s)" % (classcol, classcol))
     r_file.write("\n")



More information about the grass-commit mailing list