[GRASS-user] v.class.mlR Error

Dear GRASS GIS community,

I just started working with Grass to try some object-based analysis. I do not have much experience with programming, but learning bits on the go.
The segmentation test with uspo appears to have been ok, but I am struggling with the next step. I was suspecting the training vector created in QGIS wasn’t meeting proper standards, but I could not find a straightforward Grass module for labeling segments/ creating a training set file.

Hopefully someone can help me out.

Command output:

(Tue May 29 14:18:32 2018)
v.class.mlR -i --overwrite training_map=Training_Ben2@haarlooj_Ben_Test segments_file=C:\Users\haarlooj\Documents\CELOS\Stats_Training_Ben_test separator=comma raster_segments_map=best_myregion1_at_haarlooj_Ben_Test_rank1@haarlooj_Ben_Test train_class_column=code output_class_column=vote output_prob_column=prob classifiers=svmRadial,rf,C5.0 folds=5 partitions=10 tunelength=10 weighting_modes=smv,qbwwv weighting_metric=accuracy classification_results=X:\Projecten\Land-use Planning Marowijne\GIS en RS\Werkfolder\GRASS\v.class.mIRR_optional_output\Ben_test_classifier-Results accuracy_file=X:\Projecten\Land-use Planning Marowijne\GIS en RS\Werkfolder\GRASS\v.class.mIRR_optional_output\Ben_Test_accuracy model_details=X:\Projecten\Land-use Planning Marowijne\GIS en RS\Werkfolder\GRASS\v.class.mIRR_optional_output\Ben_Test_ClassifierDetails bw_plot_file=X:\Projecten\Land-use Planning Marowijne\GIS en RS\Werkfolder\GRASS\v.class.mIRR_optional_output\Ben_test_classifier_performance r_script_file=X:\Projecten\Land-use Planning Marowijne\GIS en RS\Werkfolder\GRASS\v.class.mIRR_optional_output\Ben_test_R_script processes=3
Running R now. Following output is R output.
Traceback (most recent call last):
File “C:\Users\haarlooj\AppData\Roaming\GRASS7\addons/scri
pts/v.class.mlR.py”, line 633, in
main()
File “C:\Users\haarlooj\AppData\Roaming\GRASS7\addons/scri
pts/v.class.mlR.py”, line 570, in main
subprocess.check_call([‘Rscript’, r_commands],
stderr=subprocess.STDOUT, )
File “C:\Program Files\GRASS GIS
7.4.0\Python27\lib\subprocess.py”, line 537, in check_call
retcode = call(*popenargs, **kwargs)
File “C:\Program Files\GRASS GIS
7.4.0\Python27\lib\subprocess.py”, line 524, in call
return Popen(*popenargs, **kwargs).wait()
File “C:\Program Files\GRASS GIS
7.4.0\Python27\lib\subprocess.py”, line 711, in init
errread, errwrite)
File “C:\Program Files\GRASS GIS
7.4.0\Python27\lib\subprocess.py”, line 948, in
_execute_child
startupinfo)
WindowsError: [Error 2] The system cannot find the file
specified
(Tue May 29 14:18:33 2018) Command finished (0 sec)

Best,
Jamille

Hi Jamille,

On 29/05/18 21:38, Jamille Haarloo wrote:

Dear GRASS GIS community,

I just started working with Grass to try some object-based analysis. I do not have much experience with programming, but learning bits on the go.
The segmentation test with uspo appears to have been ok, but I am struggling with the next step. I was suspecting the training vector created in QGIS wasn't meeting proper standards, but I could not find a straightforward Grass module for labeling segments/ creating a training set file.

Hopefully someone can help me out.

Command output:

(Tue May 29 14:18:32 2018)
v.class.mlR -i --overwrite training_map=Training_Ben2@haarlooj_Ben_Test segments_file=C:\Users\haarlooj\Documents\CELOS\Stats_Training_Ben_test separator=comma raster_segments_map=best_myregion1_at_haarlooj_Ben_Test_rank1@haarlooj_Ben_Test train_class_column=code output_class_column=vote output_prob_column=prob classifiers=svmRadial,rf,C5.0 folds=5 partitions=10 tunelength=10 weighting_modes=smv,qbwwv weighting_metric=accuracy classification_results=X:\Projecten\Land-use Planning Marowijne\GIS en RS\Werkfolder\GRASS\v.class.mIRR_optional_output\Ben_test_classifier-Results accuracy_file=X:\Projecten\Land-use Planning Marowijne\GIS en RS\Werkfolder\GRASS\v.class.mIRR_optional_output\Ben_Test_accuracy model_details=X:\Projecten\Land-use Planning Marowijne\GIS en RS\Werkfolder\GRASS\v.class.mIRR_optional_output\Ben_Test_ClassifierDetails bw_plot_file=X:\Projecten\Land-use Planning Marowijne\GIS en RS\Werkfolder\GRASS\v.class.mIRR_optional_output\Ben_test_classifier_performance r_script_file=X:\Projecten\Land-use Planning Marowijne\GIS en RS\Werkfolder\GRASS\v.class.mIRR_optional_output\Ben_test_R_script processes=3
Running R now. Following output is R output.
Traceback (most recent call last):
File "C:\Users\haarlooj\AppData\Roaming\GRASS7\addons/scri
pts/v.class.mlR.py <http://v.class.mlR.py>", line 633, in <module>
main()
File "C:\Users\haarlooj\AppData\Roaming\GRASS7\addons/scri
pts/v.class.mlR.py <http://v.class.mlR.py>", line 570, in main
subprocess.check_call(['Rscript', r_commands],
stderr=subprocess.STDOUT, )

My hunch is that the problem is some PATH issues making it difficult to call R.

Maybe some of the Windows gurus out there could help with this ?

Moritz

My hunch is that the problem is some PATH issues making it >difficult to
call R.

Maybe some of the Windows gurus out there could help with this ?

Is there a working example available for this addon?

-----
best regards
Helmut
--
Sent from: http://osgeo-org.1560.x6.nabble.com/Grass-Users-f3884509.html

On 31/05/18 09:52, Helmut Kudrnovsky wrote:

My hunch is that the problem is some PATH issues making it >difficult to
call R.

Maybe some of the Windows gurus out there could help with this ?

Is there a working example available for this addon?

Here's a complete working example of the entire OBIA chain in the NC dataset (warning: this is a demo example, not necessarily one of best practice ;-)) :

g.extension r.object.geometry
g.extension i.segment.stats
g.extension v.class.mlR

g.region rast=lsat7_2002_10 -p
i.group lsat7_2002_ms in=lsat7_2002_10,lsat7_2002_20,lsat7_2002_30,lsat7_2002_40,lsat7_2002_50,lsat7_2002_70
i.segment lsat7_2002_ms threshold=0.05 out=lsat7_segs_005 minsize=10
i.segment.stats lsat7_segs_005 rasters=lsat7_2002_10,lsat7_2002_20,lsat7_2002_30,lsat7_2002_40,lsat7_2002_50,lsat7_2002_70 vectormap=lsat7_segs_stats
v.random n=1000 out=points
v.db.addtable points
v.db.addcolumn points col="class int"
v.what.rast map=points raster=landclass96 column=class
v.db.addcolumn points col="segid int"
v.what.rast map=points raster=lsat7_segs_005 column=segid
v.db.join lsat7_segs_stats column=cat otable=points ocolumn=segid subset_col=class
v.extract lsat7_segs_stats where="class>0" output=training
v.class.mlR segments_map=lsat7_segs_stats training_map=training train_class_colum=class
r.colors.out landclass96 rules=landclass96.colors
v.colors lsat7_segs_stats use=attr column=vote_smv rules=landclass96.colors
d.vect lsat7_segs_stats

Not sure if this should go into the man pages of the different tools, or whether it might be better to integrate it into image classification wiki page's section on OBIA [1] and link to that from the different man pages.

Moritz

[1] https://grasswiki.osgeo.org/wiki/Image_classification#Object-based_classification_and_image_segmentation

Here's a complete working example of the entire OBIA chain in the NC
dataset (warning: this is a demo example, not necessarily one of best
practice ;-)) :

thanks, testing it here now.

https://trac.osgeo.org/grass/browser/grass-addons/grass7/vector/v.class.mlR/v.class.mlR.py#L278

278 install_package = "if(!is.element('%s',
installed.packages()[,1])){\n"
279 install_package += "cat('\\n\\nInstalling %s package from
CRAN\n')\n"
280 install_package += "if(!file.exists(Sys.getenv('R_LIBS_USER'))){\n"
281 install_package += "dir.create(Sys.getenv('R_LIBS_USER'),
recursive=TRUE)\n"
282 install_package += ".libPaths(Sys.getenv('R_LIBS_USER'))}\n"
283 install_package += "chooseCRANmirror(ind=1)\n"
284 install_package += "install.packages('%s', dependencies=TRUE)}"

for installling packages in windows R:

https://cran.r-project.org/bin/windows/base/rw-FAQ.html#I-don_0027t-have-permission-to-write-to-the-R_002d3_002e5_002e0_005clibrary-directory

for installing system wide in windows administrator rights are needed. maybe
some possible source of troubles.

so maybe a recommendation in the manual?: let the user install the needed
packages first in R itself, then start the grass addon.

addon test here shows:

-----------------
v.class.mlR --verbose segments_map=lsat7_segs_stats training_map=training
train_class_colum=class
Running R now. Following output is R output.
Loading required package: caret
Loading required package: lattice
Loading required package: ggplot2
There were 50 or more warnings (use warnings() to see the first 50)
Error in file(file, ifelse(append, "a", "w")) :
  cannot open the connection
Calls: write.csv -> eval.parent -> eval -> eval -> write.table -> file
In addition: Warning message:
In file(file, ifelse(append, "a", "w")) :
  cannot open file '.gscript_tmp_model_output_1300.csv': Permission denied
Execution halted
ERROR: There was an error in the execution of the R script.
Please check the R output.
-----------------

it seems, R is started, packages loaded correctly.

where is the file '.gscript_tmp_model_output_1300.csv' written to?

485 if allmap and not flags['f']:
486 model_output = '.gscript_tmp_model_output_%d.csv' % os.getpid()
487 write_string = "write.csv(resultsdf, '%s'," % model_output
488 write_string += " row.names=FALSE, quote=FALSE)"
489 r_file.write(write_string)
490 r_file.write("\n")

would it be possible to catch the R error/output?

-----
best regards
Helmut
--
Sent from: http://osgeo-org.1560.x6.nabble.com/Grass-Users-f3884509.html

Here's a complete working example of the entire OBIA chain in the NC
dataset (warning: this is a demo example, not necessarily one of best
practice ;-)) :

tested here now with -f flag in the GUI:

---------------------------------------
v.class.mlR segments_map=lsat7_segs_stats training_map=training
train_class_column=class output_class_column=vote output_prob_column=prob
folds=5 partitions=10 tunelength=10 weighting_metric=accuracy
classification_results=D:\temp\vclassr\class.txt
accuracy_file=D:\temp\vclassr\acc.txt
model_details=D:\temp\vclassr\details.txt
bw_plot_file=D:\temp\vclassr\bwplot.png
r_script_file=D:\temp\vclassr\testrunaddon.R processes=3
Running R now. Following output is R output.
Loading required package: caret
Loading required package: lattice
Loading required package: ggplot2
Loading required package: foreach
Loading required package: iterators
Loading required package: parallel
Warning message:
In nominalTrainWorkflow(x = x, y = y, wts = weights, info = trainInfo, :
  There were missing values in resampled performance measures.
Error in file(file, ifelse(append, "a", "w")) :
  cannot open the connection
Calls: write.csv -> eval.parent -> eval -> eval -> write.table -> file
In addition: Warning message:
In file(file, ifelse(append, "a", "w")) :
  cannot open file '.gscript_tmp_model_output_2392.csv': Permission denied
Execution halted
ERROR: There was an error in the execution of the R script.
Please check the R output.
---------------------------------------

attached the testrunaddon.R
<http://osgeo-org.1560.x6.nabble.com/file/t193444/testrunaddon.R&gt;

-----
best regards
Helmut
--
Sent from: http://osgeo-org.1560.x6.nabble.com/Grass-Users-f3884509.html

In file(file, ifelse(append, "a", "w")) :
cannot open file '.gscript_tmp_model_output_2392.csv': Permission denied

in the R script:

[...]
resultsdf$prob_smv <- vote$V2
write.csv(resultsdf, '.gscript_tmp_model_output_2392.csv', row.names=FALSE,
quote=FALSE)
write.csv(resultsdf, 'D:\temp\vclassr\class.txt', row.names=FALSE,
quote=FALSE)
[...]

AFAIR in windows and python, you need to specify the temp file e.g. by
python's tempfile functions that it can be found later in the process.

-----
best regards
Helmut
--
Sent from: http://osgeo-org.1560.x6.nabble.com/Grass-Users-f3884509.html

Helmut Kudrnovsky wrote

In file(file, ifelse(append, "a", "w")) :
cannot open file '.gscript_tmp_model_output_2392.csv': Permission denied

in the R script:

[...]
resultsdf$prob_smv <- vote$V2
write.csv(resultsdf, '.gscript_tmp_model_output_2392.csv',
row.names=FALSE,
quote=FALSE)
write.csv(resultsdf, 'D:\temp\vclassr\class.txt', row.names=FALSE,
quote=FALSE)
[...]

AFAIR in windows and python, you need to specify the temp file e.g. by
python's tempfile functions that it can be found later in the process.

as an example I do it in

https://trac.osgeo.org/grass/browser/grass-addons/grass7/raster/r.euro.ecosystem/r.euro.ecosystem.py#L72

72 # define intermediate folder files
73 datatempdir = tempfile.gettempdir()
74 if level1 :
75 tmp_col_l1 = os.path.join( datatempdir, color_rules_level1 )
76 tmp_cat_l1 = os.path.join( datatempdir, cat_rules_level1 )
77 if level2 :
78 tmp_col_l2 = os.path.join( datatempdir, color_rules_level2 )
79 tmp_cat_l2 = os.path.join( datatempdir, cat_rules_level2 )

maybe there are nicer and more pythonic ways to do it :wink:

-----
best regards
Helmut
--
Sent from: http://osgeo-org.1560.x6.nabble.com/Grass-Users-f3884509.html

On 31/05/18 12:16, Helmut Kudrnovsky wrote:

In file(file, ifelse(append, "a", "w")) :
cannot open file '.gscript_tmp_model_output_2392.csv': Permission denied

in the R script:

[...]
resultsdf$prob_smv <- vote$V2
write.csv(resultsdf, '.gscript_tmp_model_output_2392.csv', row.names=FALSE,
quote=FALSE)
write.csv(resultsdf, 'D:\temp\vclassr\class.txt', row.names=FALSE,
quote=FALSE)
[...]

AFAIR in windows and python, you need to specify the temp file e.g. by
python's tempfile functions that it can be found later in the process.

Thanks for testing !

You're right. I don't remember why I coded this in that manner. It might have been to ensure the .csv and .csvt suffix needed for db.in.ogr.

Could you try with below patch ?

Moritz

Index: v.class.mlR.py

--- v.class.mlR.py (révision 72333)
+++ v.class.mlR.py (copie de travail)
@@ -233,8 +233,8 @@
          gscript.try_remove(feature_vars)
      if trainmap:
          gscript.try_remove(training_vars)
- gscript.try_remove(model_output)
- gscript.try_remove(model_output_desc)
+ gscript.try_remove(model_output_csv)
+ gscript.try_remove(model_output_csvt)
      gscript.try_remove(r_commands)
      if reclass_files:
          for reclass_file in reclass_files.itervalues():
@@ -251,8 +251,8 @@
      global trainmap
      global feature_vars
      global training_vars
- global model_output
- global model_output_desc
+ global model_output_csv
+ global model_output_csvt
      global temptable
      global r_commands
      global reclass_files
@@ -483,8 +483,9 @@
              r_file.write("\n")

      if allmap and not flags['f']:
- model_output = '.gscript_tmp_model_output_%d.csv' % os.getpid()
- write_string = "write.csv(resultsdf, '%s'," % model_output
+ model_output = gscript.tempfile()
+ model_output_csv = model_output + '.csv'
+ write_string = "write.csv(resultsdf, '%s'," % model_output_csv
          write_string += " row.names=FALSE, quote=FALSE)"
          r_file.write(write_string)
          r_file.write("\n")
@@ -575,10 +576,10 @@

      if allmap and not flags['f']:

- model_output_desc = model_output + 't'
+ model_output_csvt = model_output + '.csvt'
          temptable = 'classif_tmp_table_%d' % os.getpid()

- f = open(model_output_desc, 'w')
+ f = open(model_output_csvt, 'w')
          header_string = '"Integer"'
          if flags['i']:
              for classifier in classifiers:
@@ -595,7 +596,7 @@

        gscript.message("Loading results into attribute table")
    gscript.run_command('db.in.ogr',
- input_=model_output,
+ input_=model_output_csv,
                              output=temptable,
                              overwrite=True,
                              quiet=True)

Could you try with below patch ?

unfortunately it seems copy/paste the patch from mail to a diff file doesn't
work, maybe caused by some whitespace or similar.

could you attach the patch as a file?

-----
best regards
Helmut
--
Sent from: http://osgeo-org.1560.x6.nabble.com/Grass-Users-f3884509.html

On 31/05/18 13:45, Helmut Kudrnovsky wrote:

Could you try with below patch ?

unfortunately it seems copy/paste the patch from mail to a diff file doesn't
work, maybe caused by some whitespace or similar.

could you attach the patch as a file?

Yes, obviously. Sorry for that.

I'm a bit under pressure for something completely different and am doing this (too) quickly on the side...

Moritz

(attachments)

v_class_mlR_tempfile.diff (2.14 KB)

Yes, obviously. Sorry for that.

no problem.

patch applied:

-------------
v.class.mlR --verbose segments_map=lsat7_segs_stats training_map=training
train_class_colum=class processes=3
Running R now. Following output is R output.
Loading required package: caret
Loading required package: lattice
Loading required package: ggplot2
Loading required package: foreach
Loading required package: iterators
Loading required package: parallel
Warning message:
In nominalTrainWorkflow(x = x, y = y, wts = weights, info = trainInfo, :
  There were missing values in resampled performance measures.
Error: '\g' is an unrecognized escape in character string starting "'D:\g"
<=
Execution halted
ERROR: There was an error in the execution of the R script.
Please check the R output.
Error in atexit._run_exitfuncs:
Traceback (most recent call last):
  File "C:\OSGEO4~1\apps\Python27\lib\atexit.py", line 24,
in _run_exitfuncs
    func(*targs, **kargs)
  File "C:\Users\hkmyr\AppData\Roaming\GRASS7\addons/scripts
/v.class.mlR.py", line 237, in cleanup
    gscript.try_remove(model_output_csvt)
NameError: global name 'model_output_csvt' is not defined
Error in sys.exitfunc:
Traceback (most recent call last):
  File "C:\OSGEO4~1\apps\Python27\lib\atexit.py", line 24,
in _run_exitfuncs
    func(*targs, **kargs)
  File "C:\Users\hkmyr\AppData\Roaming\GRASS7\addons/scripts
/v.class.mlR.py", line 237, in cleanup
    gscript.try_remove(model_output_csvt)
NameError: global name 'model_output_csvt' is not defined
------------

Error: '\g' is an unrecognized escape in character string starting "'D:\g"

there seems to be a path issue with shlashes

and some variables not defined.

-----
best regards
Helmut
--
Sent from: http://osgeo-org.1560.x6.nabble.com/Grass-Users-f3884509.html

Helmut Kudrnovsky wrote

Yes, obviously. Sorry for that.

no problem.

patch applied:

-------------
v.class.mlR --verbose segments_map=lsat7_segs_stats training_map=training
train_class_colum=class processes=3
Running R now. Following output is R output.
Loading required package: caret
Loading required package: lattice
Loading required package: ggplot2
Loading required package: foreach
Loading required package: iterators
Loading required package: parallel
Warning message:
In nominalTrainWorkflow(x = x, y = y, wts = weights, info = trainInfo, :
  There were missing values in resampled performance measures.
Error: '\g' is an unrecognized escape in character string starting "'D:\g"

------------

Error: '\g' is an unrecognized escape in character string starting "'D:\g"

there seems to be a path issue with shlashes

added a g.message about the temporary file:

v.class.mlR --verbose segments_map=lsat7_segs_stats training_map=training
train_class_colum=class processes=3
temporary file: D:\grassdata\nc_spm_08_grass7\user1\.tmp/unknown\10300.3.csv

AFAIR R in windows needs slashes, e.g.

getwd()

[1] "C:/Users/myuser/Documents"

-----
best regards
Helmut
--
Sent from: http://osgeo-org.1560.x6.nabble.com/Grass-Users-f3884509.html

On 31/05/18 14:25, Helmut Kudrnovsky wrote:

Helmut Kudrnovsky wrote

Yes, obviously. Sorry for that.

no problem.

patch applied:

-------------
v.class.mlR --verbose segments_map=lsat7_segs_stats training_map=training
train_class_colum=class processes=3
Running R now. Following output is R output.
Loading required package: caret
Loading required package: lattice
Loading required package: ggplot2
Loading required package: foreach
Loading required package: iterators
Loading required package: parallel
Warning message:
In nominalTrainWorkflow(x = x, y = y, wts = weights, info = trainInfo, :
   There were missing values in resampled performance measures.
Error: '\g' is an unrecognized escape in character string starting "'D:\g"

------------

Error: '\g' is an unrecognized escape in character string starting "'D:\g"

there seems to be a path issue with shlashes

added a g.message about the temporary file:

v.class.mlR --verbose segments_map=lsat7_segs_stats training_map=training
train_class_colum=class processes=3
temporary file: D:\grassdata\nc_spm_08_grass7\user1\.tmp/unknown\10300.3.csv

AFAIR R in windows needs slashes, e.g.

getwd()

[1] "C:/Users/myuser/Documents"

Right.

Would replacing tempfile() with tempfile().replace('\\', '/') in line 486 help ?

ISTR that there was a function for this somewhere, but can't find it in a quick search.

Attached the again entire patch, but with the above change.

Moritz

(attachments)

v_class_mlR_tempfile.diff (2.16 KB)

Moritz Lennert wrote

On 31/05/18 14:25, Helmut Kudrnovsky wrote:

Helmut Kudrnovsky wrote

Yes, obviously. Sorry for that.

no problem.

patch applied:

-------------
v.class.mlR --verbose segments_map=lsat7_segs_stats
training_map=training
train_class_colum=class processes=3
Running R now. Following output is R output.
Loading required package: caret
Loading required package: lattice
Loading required package: ggplot2
Loading required package: foreach
Loading required package: iterators
Loading required package: parallel
Warning message:
In nominalTrainWorkflow(x = x, y = y, wts = weights, info = trainInfo,
:
   There were missing values in resampled performance measures.
Error: '\g' is an unrecognized escape in character string starting
"'D:\g"

------------

Error: '\g' is an unrecognized escape in character string starting
"'D:\g"

there seems to be a path issue with shlashes

added a g.message about the temporary file:

v.class.mlR --verbose segments_map=lsat7_segs_stats training_map=training
train_class_colum=class processes=3
temporary file:
D:\grassdata\nc_spm_08_grass7\user1\.tmp/unknown\10300.3.csv

AFAIR R in windows needs slashes, e.g.

getwd()

[1] "C:/Users/myuser/Documents"

Right.

Would replacing tempfile() with tempfile().replace('\\', '/') in line
486 help ?

ISTR that there was a function for this somewhere, but can't find it in
a quick search.

Attached the again entire patch, but with the above change.

yes, looks good now:

-------------------------
v.class.mlR --verbose segments_map=lsat7_segs_stats training_map=training
train_class_colum=class processes=3
temporary file: D:/grassdata/nc_spm_08_grass7/user1/.tmp/unknown/13920.3.csv
Running R now. Following output is R output.
Loading required package: caret
Loading required package: lattice
Loading required package: ggplot2
Loading required package: foreach
Loading required package: iterators
Loading required package: parallel
Warning message:
In nominalTrainWorkflow(x = x, y = y, wts = weights, info = trainInfo, :
  There were missing values in resampled performance measures.
Finished running R.
Loading results into attribute table
(Thu May 31 22:12:30 2018) Command finished (2 min 45 sec)
-------------------------

-----
best regards
Helmut
--
Sent from: http://osgeo-org.1560.x6.nabble.com/Grass-Users-f3884509.html

Le Thu, 31 May 2018 13:14:39 -0700 (MST),
Helmut Kudrnovsky <hellik@web.de> a écrit :

Moritz Lennert wrote
> On 31/05/18 14:25, Helmut Kudrnovsky wrote:
>> Helmut Kudrnovsky wrote
>>>> Yes, obviously. Sorry for that.
>>>
>>> no problem.
>>>
>>> patch applied:
>>>
>>> -------------
>>> v.class.mlR --verbose segments_map=lsat7_segs_stats
>>> training_map=training
>>> train_class_colum=class processes=3
>>> Running R now. Following output is R output.
>>> Loading required package: caret
>>> Loading required package: lattice
>>> Loading required package: ggplot2
>>> Loading required package: foreach
>>> Loading required package: iterators
>>> Loading required package: parallel
>>> Warning message:
>>> In nominalTrainWorkflow(x = x, y = y, wts = weights, info =
>>> trainInfo, :
>>> There were missing values in resampled performance measures.
>>> Error: '\g' is an unrecognized escape in character string starting
>>> "'D:\g"
>>>
>>> ------------
>>>
>>> Error: '\g' is an unrecognized escape in character string starting
>>> "'D:\g"
>>>
>>> there seems to be a path issue with shlashes
>>
>> added a g.message about the temporary file:
>>
>> v.class.mlR --verbose segments_map=lsat7_segs_stats
>> training_map=training train_class_colum=class processes=3
>> temporary file:
>> D:\grassdata\nc_spm_08_grass7\user1\.tmp/unknown\10300.3.csv
>>
>> AFAIR R in windows needs slashes, e.g.
>>
>>> getwd()
>> [1] "C:/Users/myuser/Documents"
>
>
> Right.
>
> Would replacing tempfile() with tempfile().replace('\\', '/') in
> line 486 help ?
>
> ISTR that there was a function for this somewhere, but can't find
> it in a quick search.
>
> Attached the again entire patch, but with the above change.

yes, looks good now:

Great, thanks for the testing and feedback.

This said, if I understand the OP's message, the issue was in finding
Rscript in MS Windows. Do you have any recommendation on this ?

Moritz

This said, if I understand the OP's message, the issue was in finding
Rscript in MS Windows.

looking at the original report:

-------------------
[...]
Running R now. Following output is R output.
Traceback (most recent call last):
  File "C:\Users\haarlooj\AppData\Roaming\GRASS7\addons/scri
pts/v.class.mlR.py", line 633, in <module>
    main()
  File "C:\Users\haarlooj\AppData\Roaming\GRASS7\addons/scri
pts/v.class.mlR.py", line 570, in main
    subprocess.check_call(['Rscript', r_commands],
stderr=subprocess.STDOUT, )
  File "C:\Program Files\GRASS GIS
7.4.0\Python27\lib\subprocess.py", line 537, in check_call
    retcode = call(*popenargs, **kwargs)
  File "C:\Program Files\GRASS GIS
7.4.0\Python27\lib\subprocess.py", line 524, in call
    return Popen(*popenargs, **kwargs).wait()
  File "C:\Program Files\GRASS GIS
7.4.0\Python27\lib\subprocess.py", line 711, in __init__
    errread, errwrite)
  File "C:\Program Files\GRASS GIS
7.4.0\Python27\lib\subprocess.py", line 948, in
_execute_child
    startupinfo)
WindowsError: [Error 2] The system cannot find the file
specified
-------------------

yes, it seems it's the issue finding the Rscript.

Do you have any recommendation on this ?

the tempfile and the path to it has to be properly build, acknowledging to
operating system characteristics; and, as in this case, considering the
peculiarity of involved 3rd party software.

e.g.

# path in windows

D:\temp\vclassr

vs.

# path in R in windows

D:/temp/vclassr

but don't be confused [1] [2], windows operating system also understands
D:/temp/vclassr, e.g. you can cd in the command line or open it in the
windows explorer ;-D ...

[1]
https://bytes.com/topic/python/answers/23123-when-did-windows-start-accepting-forward-slash-path-separator

[2]
https://www.howtogeek.com/181774/why-windows-uses-backslashes-and-everything-else-uses-forward-slashes/

-----
best regards
Helmut
--
Sent from: http://osgeo-org.1560.x6.nabble.com/Grass-Users-f3884509.html

Am 31. Mai 2018 22:43:58 MESZ schrieb Helmut Kudrnovsky <hellik@web.de>:

This said, if I understand the OP's message, the issue was in finding
Rscript in MS Windows.

looking at the original report:

-------------------
[...]
Running R now. Following output is R output.
Traceback (most recent call last):
File "C:\Users\haarlooj\AppData\Roaming\GRASS7\addons/scri
pts/v.class.mlR.py", line 633, in <module>
   main()
File "C:\Users\haarlooj\AppData\Roaming\GRASS7\addons/scri
pts/v.class.mlR.py", line 570, in main
   subprocess.check_call(['Rscript', r_commands],
stderr=subprocess.STDOUT, )
File "C:\Program Files\GRASS GIS
7.4.0\Python27\lib\subprocess.py", line 537, in check_call
   retcode = call(*popenargs, **kwargs)
File "C:\Program Files\GRASS GIS
7.4.0\Python27\lib\subprocess.py", line 524, in call
   return Popen(*popenargs, **kwargs).wait()
File "C:\Program Files\GRASS GIS
7.4.0\Python27\lib\subprocess.py", line 711, in __init__
   errread, errwrite)
File "C:\Program Files\GRASS GIS
7.4.0\Python27\lib\subprocess.py", line 948, in
_execute_child
   startupinfo)
WindowsError: [Error 2] The system cannot find the file
specified
-------------------

yes, it seems it's the issue finding the Rscript.

Do you have any recommendation on this ?

the tempfile and the path to it has to be properly build,

But it's not about the tempfile, it's about calling Rscript and Windows not being able to find it, or ? Some paths to set correctly maybe ?

Moritz

But it's not about the tempfile, it's about calling Rscript and >Windows not

being able to find it, or ?

looking closer at the report and the used command, the Rscript and other
files should be written to files in some folder, right?

>Some paths to set correctly maybe ?

What I've seen today during quick tests, it may be the path can't be
resolved, it may be a similar issue with path like for the temp File.

But in my first quuck test, the Rscript was written to a folder when
specified.

I suggest to apply a patch in svn to solve the temp file issue, then further
testing is needed.

-----
best regards
Helmut
--
Sent from: http://osgeo-org.1560.x6.nabble.com/Grass-Users-f3884509.html

On 01/06/18 00:41, Helmut Kudrnovsky wrote:

But it's not about the tempfile, it's about calling Rscript and >Windows not

being able to find it, or ?

looking closer at the report and the used command, the Rscript and other
files should be written to files in some folder, right?

Rscript is an executable which allows to call R commands non-interactively in a scripting environment.

However, I noticed that the file with the R commands was the only one I hadn't done the replace("\\", "/") on, so maybe the error about not being able to find the file is about the command file, not Rscript.

  >Some paths to set correctly maybe ?

What I've seen today during quick tests, it may be the path can't be
resolved, it may be a similar issue with path like for the temp File.

But in my first quuck test, the Rscript was written to a folder when
specified.

I suggest to apply a patch in svn to solve the temp file issue, then further
testing is needed.

I committed a patch in r72758 which now correctly applies the replace() call to all tempfiles created. Please test.

If you still see an error that combines

pts/v.class.mlR.py", line 570, in main
     subprocess.check_call(['Rscript', r_commands],
stderr=subprocess.STDOUT, )

and

WindowsError: [Error 2] The system cannot find the file
specified

Then maybe it is about Rscript not being in the PATH...

Jamille, could you please also test ? It should be available for Windows for installation with g.extension by tomorrow.

Moritz