2012-10-05 23:28:47 +02:00
# -*- coding: utf-8 -*-
"""
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
RAlgorithm . py
- - - - - - - - - - - - - - - - - - - - -
Date : August 2012
Copyright : ( C ) 2012 by Victor Olaya
Email : volayaf at gmail dot com
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* This program is free software ; you can redistribute it and / or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation ; either version 2 of the License , or *
* ( at your option ) any later version . *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
"""
__author__ = ' Victor Olaya '
__date__ = ' August 2012 '
__copyright__ = ' (C) 2012, Victor Olaya '
2013-10-01 20:52:22 +03:00
2012-10-05 23:28:47 +02:00
# This will get replaced with a git SHA1 when you do a git archive
2013-10-01 20:52:22 +03:00
2012-10-05 23:28:47 +02:00
__revision__ = ' $Format: % H$ '
2012-09-15 18:25:25 +03:00
import os
2013-10-01 20:52:22 +03:00
import subprocess
2012-09-15 18:25:25 +03:00
from PyQt4 . QtCore import *
from PyQt4 . QtGui import *
from PyQt4 import QtGui , QtCore
2013-08-12 20:44:27 +02:00
from processing . core . GeoAlgorithm import GeoAlgorithm
2013-10-01 20:52:22 +03:00
from processing . core . GeoAlgorithmExecutionException import \
GeoAlgorithmExecutionException
from processing . core . ProcessingLog import ProcessingLog
from processing . core . ProcessingConfig import ProcessingConfig
from processing . gui . Help2Html import Help2Html
2013-08-12 20:44:27 +02:00
from processing . parameters . ParameterRaster import ParameterRaster
from processing . parameters . ParameterTable import ParameterTable
from processing . parameters . ParameterVector import ParameterVector
from processing . parameters . ParameterMultipleInput import ParameterMultipleInput
from processing . parameters . ParameterString import ParameterString
from processing . parameters . ParameterNumber import ParameterNumber
from processing . parameters . ParameterBoolean import ParameterBoolean
from processing . parameters . ParameterSelection import ParameterSelection
from processing . parameters . ParameterTableField import ParameterTableField
from processing . parameters . ParameterExtent import ParameterExtent
from processing . parameters . ParameterFile import ParameterFile
2013-10-01 20:52:22 +03:00
from processing . outputs . OutputTable import OutputTable
from processing . outputs . OutputVector import OutputVector
from processing . outputs . OutputRaster import OutputRaster
from processing . outputs . OutputHTML import OutputHTML
2013-08-12 20:44:27 +02:00
from processing . outputs . OutputFile import OutputFile
2013-10-01 20:52:22 +03:00
from processing . tools . system import *
from processing . script . WrongScriptException import WrongScriptException
from processing . r . RUtils import RUtils
2012-09-15 18:25:25 +03:00
class RAlgorithm ( GeoAlgorithm ) :
2013-10-01 20:52:22 +03:00
R_CONSOLE_OUTPUT = ' R_CONSOLE_OUTPUT '
RPLOTS = ' RPLOTS '
2012-09-15 18:25:25 +03:00
def getCopy ( self ) :
newone = RAlgorithm ( self . descriptionFile )
newone . provider = self . provider
return newone
def __init__ ( self , descriptionFile , script = None ) :
GeoAlgorithm . __init__ ( self )
self . script = script
self . descriptionFile = descriptionFile
if script is not None :
self . defineCharacteristicsFromScript ( )
if descriptionFile is not None :
self . defineCharacteristicsFromFile ( )
def getIcon ( self ) :
2013-10-01 20:52:22 +03:00
return QtGui . QIcon ( os . path . dirname ( __file__ ) + ' /../images/r.png ' )
2012-09-15 18:25:25 +03:00
def defineCharacteristicsFromScript ( self ) :
2013-10-01 20:52:22 +03:00
lines = self . script . split ( ' \n ' )
self . name = ' [Unnamed algorithm] '
self . group = ' User R scripts '
2013-03-20 21:50:40 +01:00
self . parseDescription ( iter ( lines ) )
2013-03-26 14:15:12 +01:00
def defineCharacteristicsFromFile ( self ) :
2013-03-20 21:50:40 +01:00
filename = os . path . basename ( self . descriptionFile )
2013-10-01 20:52:22 +03:00
self . name = filename [ : filename . rfind ( ' . ' ) ] . replace ( ' _ ' , ' ' )
self . group = ' User R scripts '
2013-03-20 21:50:40 +01:00
with open ( self . descriptionFile , ' r ' ) as f :
lines = [ line . strip ( ) for line in f ]
self . parseDescription ( iter ( lines ) )
2013-03-26 14:15:12 +01:00
def parseDescription ( self , lines ) :
2013-10-01 20:52:22 +03:00
self . script = ' '
self . commands = [ ]
2012-09-15 18:25:25 +03:00
self . showPlots = False
self . showConsoleOutput = False
2013-03-10 21:10:53 +01:00
self . useRasterPackage = True
2013-02-23 15:44:44 +01:00
self . passFileNames = False
2012-09-15 18:25:25 +03:00
self . verboseCommands = [ ]
2013-03-26 14:15:12 +01:00
ender = 0
2013-10-01 20:52:22 +03:00
line = lines . next ( ) . strip ( ' \n ' ) . strip ( ' \r ' )
2013-03-07 08:49:12 +01:00
while ender < 10 :
2013-10-01 20:52:22 +03:00
if line . startswith ( ' ## ' ) :
2012-09-15 18:25:25 +03:00
try :
self . processParameterLine ( line )
except Exception :
2013-10-01 20:52:22 +03:00
raise WrongScriptException ( ' Could not load R script: '
+ self . descriptionFile + ' . \n Problem with line " '
+ line + ' " ' )
elif line . startswith ( ' > ' ) :
2012-09-15 18:25:25 +03:00
self . commands . append ( line [ 1 : ] )
self . verboseCommands . append ( line [ 1 : ] )
if not self . showConsoleOutput :
2013-10-01 20:52:22 +03:00
self . addOutput ( OutputHTML ( RAlgorithm . R_CONSOLE_OUTPUT ,
' R Console Output ' ) )
2012-09-15 18:25:25 +03:00
self . showConsoleOutput = True
else :
2013-03-07 08:49:12 +01:00
if line == ' ' :
ender + = 1
else :
2013-10-01 20:52:22 +03:00
ender = 0
2012-09-15 18:25:25 +03:00
self . commands . append ( line )
2013-10-01 20:52:22 +03:00
self . script + = line + ' \n '
2013-03-20 21:50:40 +01:00
try :
2013-10-01 20:52:22 +03:00
line = lines . next ( ) . strip ( ' \n ' ) . strip ( ' \r ' )
2013-03-20 21:50:40 +01:00
except :
break
2012-09-15 18:25:25 +03:00
def getVerboseCommands ( self ) :
return self . verboseCommands
def createDescriptiveName ( self , s ) :
2013-10-01 20:52:22 +03:00
return s . replace ( ' _ ' , ' ' )
2012-09-15 18:25:25 +03:00
2013-10-01 20:52:22 +03:00
def processParameterLine ( self , line ) :
2012-09-15 18:25:25 +03:00
param = None
out = None
2013-10-01 20:52:22 +03:00
line = line . replace ( ' # ' , ' ' )
if line . lower ( ) . strip ( ) . startswith ( ' showplots ' ) :
2012-09-15 18:25:25 +03:00
self . showPlots = True
2013-10-01 20:52:22 +03:00
self . addOutput ( OutputHTML ( RAlgorithm . RPLOTS , ' R Plots ' ) )
2012-09-15 18:25:25 +03:00
return
2013-10-01 20:52:22 +03:00
if line . lower ( ) . strip ( ) . startswith ( ' dontuserasterpackage ' ) :
2013-03-10 21:10:53 +01:00
self . useRasterPackage = False
2013-02-28 22:08:32 +01:00
return
2013-10-01 20:52:22 +03:00
if line . lower ( ) . strip ( ) . startswith ( ' passfilenames ' ) :
2013-02-23 15:44:44 +01:00
self . passFileNames = True
return
2013-10-01 20:52:22 +03:00
tokens = line . split ( ' = ' )
2012-09-15 18:25:25 +03:00
desc = self . createDescriptiveName ( tokens [ 0 ] )
2013-10-01 20:52:22 +03:00
if tokens [ 1 ] . lower ( ) . strip ( ) == ' group ' :
2012-09-15 18:25:25 +03:00
self . group = tokens [ 0 ]
return
2013-10-01 20:52:22 +03:00
if tokens [ 1 ] . lower ( ) . strip ( ) . startswith ( ' raster ' ) :
2012-09-15 18:25:25 +03:00
param = ParameterRaster ( tokens [ 0 ] , desc , False )
2013-10-01 20:52:22 +03:00
elif tokens [ 1 ] . lower ( ) . strip ( ) == ' vector ' :
param = ParameterVector ( tokens [ 0 ] , desc ,
[ ParameterVector . VECTOR_TYPE_ANY ] )
elif tokens [ 1 ] . lower ( ) . strip ( ) == ' table ' :
2012-09-15 18:25:25 +03:00
param = ParameterTable ( tokens [ 0 ] , desc , False )
2013-10-01 20:52:22 +03:00
elif tokens [ 1 ] . lower ( ) . strip ( ) . startswith ( ' multiple raster ' ) :
param = ParameterMultipleInput ( tokens [ 0 ] , desc ,
ParameterMultipleInput . TYPE_RASTER )
2012-09-15 18:25:25 +03:00
param . optional = False
2013-10-01 20:52:22 +03:00
elif tokens [ 1 ] . lower ( ) . strip ( ) == ' multiple vector ' :
param = ParameterMultipleInput ( tokens [ 0 ] , desc ,
ParameterMultipleInput . TYPE_VECTOR_ANY )
2012-09-15 18:25:25 +03:00
param . optional = False
2013-10-01 20:52:22 +03:00
elif tokens [ 1 ] . lower ( ) . strip ( ) . startswith ( ' selection ' ) :
options = tokens [ 1 ] . strip ( ) [ len ( ' selection ' ) : ] . split ( ' ; ' )
param = ParameterSelection ( tokens [ 0 ] , desc , options )
elif tokens [ 1 ] . lower ( ) . strip ( ) . startswith ( ' boolean ' ) :
default = tokens [ 1 ] . strip ( ) [ len ( ' boolean ' ) + 1 : ]
param = ParameterBoolean ( tokens [ 0 ] , desc , default )
elif tokens [ 1 ] . lower ( ) . strip ( ) . startswith ( ' number ' ) :
2012-09-15 18:25:25 +03:00
try :
2013-10-01 20:52:22 +03:00
default = float ( tokens [ 1 ] . strip ( ) [ len ( ' number ' ) + 1 : ] )
param = ParameterNumber ( tokens [ 0 ] , desc , default = default )
2012-09-15 18:25:25 +03:00
except :
2013-10-01 20:52:22 +03:00
raise WrongScriptException ( ' Could not load R script: '
+ self . descriptionFile + ' . \n Problem with line " '
+ line + ' " ' )
elif tokens [ 1 ] . lower ( ) . strip ( ) . startswith ( ' field ' ) :
field = tokens [ 1 ] . strip ( ) [ len ( ' field ' ) + 1 : ]
2012-09-15 18:25:25 +03:00
found = False
for p in self . parameters :
if p . name == field :
found = True
break
if found :
2013-10-01 20:52:22 +03:00
param = ParameterTableField ( tokens [ 0 ] , tokens [ 0 ] , field )
elif tokens [ 1 ] . lower ( ) . strip ( ) == ' extent ' :
param = ParameterExtent ( tokens [ 0 ] , desc )
elif tokens [ 1 ] . lower ( ) . strip ( ) == ' file ' :
param = ParameterFile ( tokens [ 0 ] , desc , False )
elif tokens [ 1 ] . lower ( ) . strip ( ) == ' folder ' :
param = ParameterFile ( tokens [ 0 ] , desc , True )
elif tokens [ 1 ] . lower ( ) . strip ( ) . startswith ( ' string ' ) :
default = tokens [ 1 ] . strip ( ) [ len ( ' string ' ) + 1 : ]
param = ParameterString ( tokens [ 0 ] , desc , default )
elif tokens [ 1 ] . lower ( ) . strip ( ) . startswith ( ' output raster ' ) :
2012-09-15 18:25:25 +03:00
out = OutputRaster ( )
2013-10-01 20:52:22 +03:00
elif tokens [ 1 ] . lower ( ) . strip ( ) . startswith ( ' output vector ' ) :
2012-09-15 18:25:25 +03:00
out = OutputVector ( )
2013-10-01 20:52:22 +03:00
elif tokens [ 1 ] . lower ( ) . strip ( ) . startswith ( ' output table ' ) :
2012-09-15 18:25:25 +03:00
out = OutputTable ( )
2013-10-01 20:52:22 +03:00
elif tokens [ 1 ] . lower ( ) . strip ( ) . startswith ( ' output file ' ) :
2012-09-15 18:25:25 +03:00
out = OutputFile ( )
2013-10-01 20:52:22 +03:00
if param is not None :
2012-09-15 18:25:25 +03:00
self . addParameter ( param )
2013-10-01 20:52:22 +03:00
elif out is not None :
2012-09-15 18:25:25 +03:00
out . name = tokens [ 0 ]
out . description = tokens [ 0 ]
self . addOutput ( out )
else :
2013-10-01 20:52:22 +03:00
raise WrongScriptException ( ' Could not load R script: '
+ self . descriptionFile
+ ' . \n Problem with line " ' + line + ' " '
)
2012-09-15 18:25:25 +03:00
def processAlgorithm ( self , progress ) :
2013-09-12 13:19:00 +02:00
if isWindows ( ) :
2012-09-15 18:25:25 +03:00
path = RUtils . RFolder ( )
2013-10-01 20:52:22 +03:00
if path == ' ' :
raise GeoAlgorithmExecutionException (
' R folder is not configured. \n Please configure it \
before running R scripts . ' )
2012-09-15 18:25:25 +03:00
loglines = [ ]
2013-10-01 20:52:22 +03:00
loglines . append ( ' R execution commands ' )
2012-09-15 18:25:25 +03:00
loglines + = self . getFullSetOfRCommands ( )
for line in loglines :
progress . setCommand ( line )
2013-08-12 20:44:27 +02:00
ProcessingLog . addToLog ( ProcessingLog . LOG_INFO , loglines )
2012-09-15 18:25:25 +03:00
RUtils . executeRAlgorithm ( self , progress )
if self . showPlots :
htmlfilename = self . getOutputValue ( RAlgorithm . RPLOTS )
2013-10-01 20:52:22 +03:00
f = open ( htmlfilename , ' w ' )
f . write ( ' <img src= " ' + self . plotsFilename + ' " /> ' )
2012-09-15 18:25:25 +03:00
f . close ( )
if self . showConsoleOutput :
htmlfilename = self . getOutputValue ( RAlgorithm . R_CONSOLE_OUTPUT )
2013-10-01 20:52:22 +03:00
f = open ( htmlfilename , ' w ' )
2012-09-15 18:25:25 +03:00
f . write ( RUtils . getConsoleOutput ( ) )
f . close ( )
def getFullSetOfRCommands ( self ) :
commands = [ ]
commands + = self . getImportCommands ( )
commands + = self . getRCommands ( )
commands + = self . getExportCommands ( )
return commands
def getExportCommands ( self ) :
commands = [ ]
for out in self . outputs :
if isinstance ( out , OutputRaster ) :
value = out . value
2013-10-01 20:52:22 +03:00
value = value . replace ( ' \\ ' , ' / ' )
2013-02-26 12:46:28 +01:00
if self . useRasterPackage or self . passFileNames :
2013-10-01 20:52:22 +03:00
commands . append ( ' writeRaster( ' + out . name + ' , " ' + value
+ ' " , overwrite=TRUE) ' )
2013-02-07 23:30:53 +01:00
else :
2013-10-01 20:52:22 +03:00
if not value . endswith ( ' tif ' ) :
value = value + ' .tif '
commands . append ( ' writeGDAL( ' + out . name + ' , " ' + value
+ ' " ) ' )
2012-09-15 18:25:25 +03:00
if isinstance ( out , OutputVector ) :
value = out . value
2013-10-01 20:52:22 +03:00
if not value . endswith ( ' shp ' ) :
value = value + ' .shp '
value = value . replace ( ' \\ ' , ' / ' )
2012-09-15 18:25:25 +03:00
filename = os . path . basename ( value )
filename = filename [ : - 4 ]
2013-10-01 20:52:22 +03:00
commands . append ( ' writeOGR( ' + out . name + ' , " ' + value + ' " , " '
+ filename + ' " , driver= " ESRI Shapefile " ) ' )
2012-09-15 18:25:25 +03:00
if self . showPlots :
2013-10-01 20:52:22 +03:00
commands . append ( ' dev.off() ' )
2012-09-15 18:25:25 +03:00
return commands
def getImportCommands ( self ) :
commands = [ ]
2013-07-21 21:53:27 +02:00
2013-10-01 20:52:22 +03:00
# Just use main mirror
2013-02-25 17:25:04 +01:00
commands . append ( ' options( " repos " = " http://cran.at.r-project.org/ " ) ' )
2013-07-21 21:53:27 +02:00
2013-10-01 20:52:22 +03:00
# Try to install packages if needed
2013-07-18 17:16:16 +02:00
packages = RUtils . getRequiredPackages ( self . script )
packages . extend ( [ ' rgdal ' , ' raster ' ] )
2013-07-21 21:53:27 +02:00
for p in packages :
2013-10-01 20:52:22 +03:00
commands . append ( ' tryCatch(find.package( " ' + p
+ ' " ), error=function(e) install.packages( " ' + p
+ ' " , dependencies=TRUE)) ' )
2013-07-18 17:16:16 +02:00
commands . append ( ' library( " raster " ) ' )
commands . append ( ' library( " rgdal " ) ' )
2013-03-26 14:15:12 +01:00
2012-09-15 18:25:25 +03:00
for param in self . parameters :
if isinstance ( param , ParameterRaster ) :
value = param . value
2013-10-01 20:52:22 +03:00
value = value . replace ( ' \\ ' , ' / ' )
2013-02-23 15:44:44 +01:00
if self . passFileNames :
2013-10-01 20:52:22 +03:00
commands . append ( param . name + ' = " ' + value + ' " ' )
2013-02-23 15:44:44 +01:00
elif self . useRasterPackage :
2013-10-01 20:52:22 +03:00
commands . append ( param . name + ' = ' + ' brick( " ' + value
+ ' " ) ' )
2013-02-07 23:30:53 +01:00
else :
2013-10-01 20:52:22 +03:00
commands . append ( param . name + ' = ' + ' readGDAL( " ' + value
+ ' " ) ' )
2012-09-15 18:25:25 +03:00
if isinstance ( param , ParameterVector ) :
value = param . getSafeExportedLayer ( )
2013-10-01 20:52:22 +03:00
value = value . replace ( ' \\ ' , ' / ' )
2012-09-15 18:25:25 +03:00
filename = os . path . basename ( value )
filename = filename [ : - 4 ]
2012-12-08 22:47:41 +01:00
folder = os . path . dirname ( value )
2013-02-23 15:44:44 +01:00
if self . passFileNames :
2013-10-01 20:52:22 +03:00
commands . append ( param . name + ' = " ' + value + ' " ' )
2013-02-23 15:44:44 +01:00
else :
2013-10-01 20:52:22 +03:00
commands . append ( param . name + ' = readOGR( " ' + folder
+ ' " ,layer= " ' + filename + ' " ) ' )
2012-09-15 18:25:25 +03:00
if isinstance ( param , ParameterTable ) :
2013-02-28 22:08:32 +01:00
value = param . value
2013-10-01 20:52:22 +03:00
if not value . lower ( ) . endswith ( ' csv ' ) :
raise GeoAlgorithmExecutionException (
' Unsupported input file format. \n ' + value )
2013-02-23 15:44:44 +01:00
if self . passFileNames :
2013-10-01 20:52:22 +03:00
commands . append ( param . name + ' = " ' + value + ' " ' )
2013-02-23 15:44:44 +01:00
else :
2013-10-01 20:52:22 +03:00
commands . append ( param . name + ' <- read.csv( " ' + value
+ ' " , head=TRUE, sep= " , " ) ' )
elif isinstance ( param , ( ParameterTableField , ParameterString ,
ParameterFile ) ) :
commands . append ( param . name + ' = " ' + param . value + ' " ' )
2013-02-23 15:44:44 +01:00
elif isinstance ( param , ( ParameterNumber , ParameterSelection ) ) :
2013-10-01 20:52:22 +03:00
commands . append ( param . name + ' = ' + str ( param . value ) )
2013-02-23 15:44:44 +01:00
elif isinstance ( param , ParameterBoolean ) :
2012-09-15 18:25:25 +03:00
if param . value :
2013-10-01 20:52:22 +03:00
commands . append ( param . name + ' =TRUE ' )
2012-09-15 18:25:25 +03:00
else :
2013-10-01 20:52:22 +03:00
commands . append ( param . name + ' =FALSE ' )
2013-02-23 15:44:44 +01:00
elif isinstance ( param , ParameterMultipleInput ) :
2013-10-01 20:52:22 +03:00
iLayer = 0
2012-09-15 18:25:25 +03:00
if param . datatype == ParameterMultipleInput . TYPE_RASTER :
2013-10-01 20:52:22 +03:00
layers = param . value . split ( ' ; ' )
2012-09-15 18:25:25 +03:00
for layer in layers :
2013-10-01 20:52:22 +03:00
layer = layer . replace ( ' \\ ' , ' / ' )
2013-02-23 15:44:44 +01:00
if self . passFileNames :
2013-10-01 20:52:22 +03:00
commands . append ( ' tempvar ' + str ( iLayer ) + ' <- " '
+ layer + ' " ' )
2013-02-23 15:44:44 +01:00
elif self . useRasterPackage :
2013-10-01 20:52:22 +03:00
commands . append ( ' tempvar ' + str ( iLayer ) + ' <- '
+ ' brick( " ' + layer + ' " ) ' )
2013-02-07 23:30:53 +01:00
else :
2013-10-01 20:52:22 +03:00
commands . append ( ' tempvar ' + str ( iLayer ) + ' <- '
+ ' readGDAL( " ' + layer + ' " ) ' )
iLayer + = 1
2012-09-15 18:25:25 +03:00
else :
exported = param . getSafeExportedLayers ( )
2013-10-01 20:52:22 +03:00
layers = exported . split ( ' ; ' )
2012-09-15 18:25:25 +03:00
for layer in layers :
2013-10-01 20:52:22 +03:00
if not layer . lower ( ) . endswith ( ' shp ' ) \
and not self . passFileNames :
raise GeoAlgorithmExecutionException (
' Unsupported input file format. \n ' + layer )
layer = layer . replace ( ' \\ ' , ' / ' )
2012-09-15 18:25:25 +03:00
filename = os . path . basename ( layer )
filename = filename [ : - 4 ]
2013-02-23 15:44:44 +01:00
if self . passFileNames :
2013-10-01 20:52:22 +03:00
commands . append ( ' tempvar ' + str ( iLayer ) + ' <- " '
+ layer + ' " ' )
2013-02-23 15:44:44 +01:00
else :
2013-10-01 20:52:22 +03:00
commands . append ( ' tempvar ' + str ( iLayer ) + ' <- '
+ ' readOGR( " ' + layer + ' " ,layer= " '
+ filename + ' " ) ' )
iLayer + = 1
s = ' '
2012-09-15 18:25:25 +03:00
s + = param . name
2013-10-01 20:52:22 +03:00
s + = ' = c( '
2012-09-15 18:25:25 +03:00
iLayer = 0
for layer in layers :
if iLayer != 0 :
2013-10-01 20:52:22 +03:00
s + = ' , '
s + = ' tempvar ' + str ( iLayer )
2012-09-15 18:25:25 +03:00
iLayer + = 1
2013-10-01 20:52:22 +03:00
s + = ' ) \n '
2012-09-15 18:25:25 +03:00
commands . append ( s )
if self . showPlots :
htmlfilename = self . getOutputValue ( RAlgorithm . RPLOTS )
2013-10-01 20:52:22 +03:00
self . plotsFilename = htmlfilename + ' .png '
self . plotsFilename = self . plotsFilename . replace ( ' \\ ' , ' / ' )
commands . append ( ' png( " ' + self . plotsFilename + ' " ) ' )
2012-09-15 18:25:25 +03:00
return commands
def getRCommands ( self ) :
return self . commands
def helpFile ( self ) :
2013-10-01 20:52:22 +03:00
helpfile = unicode ( self . descriptionFile ) + ' .help '
2012-09-15 18:25:25 +03:00
if os . path . exists ( helpfile ) :
h2h = Help2Html ( )
return h2h . getHtmlFile ( self , helpfile )
else :
return None
def checkBeforeOpeningParametersDialog ( self ) :
2013-07-18 17:16:16 +02:00
msg = RUtils . checkRIsInstalled ( )
if msg is not None :
2013-10-01 20:52:22 +03:00
html = ' <p>This algorithm requires R to be run.Unfortunately, \
it seems that R is not installed in your system , or it \
is not correctly configured to be used from QGIS < / p > '
2013-08-12 20:44:27 +02:00
html + = ' <p><a href= " http://docs.qgis.org/2.0/html/en/docs/user_manual/processing/3rdParty.html " >Click here</a> to know more about how to install and configure R to be used with QGIS</p> '
2013-07-18 17:16:16 +02:00
return html
def getPostProcessingErrorMessage ( self , wrongLayers ) :
html = GeoAlgorithm . getPostProcessingErrorMessage ( self , wrongLayers )
msg = RUtils . checkRIsInstalled ( True )
2013-10-01 20:52:22 +03:00
html + = ' <p>This algorithm requires R to be run. A test to check if \
R is correctly installed and configured in your system has \
been performed , with the following result : < / p > < ul > < i > '
2013-07-18 17:16:16 +02:00
if msg is None :
2013-10-01 20:52:22 +03:00
html + = ' R seems to be correctly installed and \
configured < / i > < / li > < / ul > '
html + = ' <p>The script you have executed needs the following \
packages : < / p > < ul > '
2013-07-18 17:16:16 +02:00
packages = RUtils . getRequiredPackages ( self . script )
for p in packages :
2013-07-21 21:53:27 +02:00
html + = ' <li> ' + p + ' </li> '
2013-10-01 20:52:22 +03:00
html + = ' </ul><p>Make sure they are installed in your R \
environment before trying to execute this script . < / p > '
2012-09-15 18:25:25 +03:00
else :
2013-10-01 20:52:22 +03:00
html + = msg + ' </i></li></ul> '
2013-08-12 20:44:27 +02:00
html + = ' <p><a href= " http://docs.qgis.org/2.0/html/en/docs/user_manual/processing/3rdParty.html " >Click here</a> to know more about how to install and configure R to be used with QGIS</p> '
2012-09-15 18:25:25 +03:00
2013-07-18 17:16:16 +02:00
return html