File tree Expand file tree Collapse file tree 3 files changed +18
-1
lines changed
python/plugins/processing/algs/r Expand file tree Collapse file tree 3 files changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -285,6 +285,8 @@ def getImportCommands(self):
285285 commands .append ('options("repos"="http://cran.at.r-project.org/")' )
286286
287287 # Try to install packages if needed
288+ if isWindows ():
289+ commands .append ('.libPaths(\" ' + str (RUtils .RLibs ()).replace ('\\ ' ,'/' ) + '\" )' )
288290 packages = RUtils .getRequiredPackages (self .script )
289291 packages .extend (['rgdal' , 'raster' ])
290292 for p in packages :
Original file line number Diff line number Diff line change @@ -61,6 +61,9 @@ def initializeSettings(self):
6161 ProcessingConfig .addSetting (Setting (
6262 self .getDescription (),
6363 RUtils .R_FOLDER , self .tr ('R folder' ), RUtils .RFolder ()))
64+ ProcessingConfig .addSetting (Setting (
65+ self .getDescription (),
66+ RUtils .R_LIBS_USER , self .tr ('R user library folder' ), RUtils .RLibs ()))
6467 ProcessingConfig .addSetting (Setting (
6568 self .getDescription (),
6669 RUtils .R_USE64 , self .tr ('Use 64 bit version' ), False ))
@@ -70,6 +73,7 @@ def unload(self):
7073 ProcessingConfig .removeSetting (RUtils .RSCRIPTS_FOLDER )
7174 if isWindows ():
7275 ProcessingConfig .removeSetting (RUtils .R_FOLDER )
76+ ProcessingConfig .removeSetting (RUtils .R_LIBS_USER )
7377 ProcessingConfig .removeSetting (RUtils .R_USE64 )
7478
7579 def getIcon (self ):
Original file line number Diff line number Diff line change @@ -41,6 +41,7 @@ class RUtils:
4141 RSCRIPTS_FOLDER = 'R_SCRIPTS_FOLDER'
4242 R_FOLDER = 'R_FOLDER'
4343 R_USE64 = 'R_USE64'
44+ R_LIBS_USER = 'R_LIBS_USER'
4445
4546 @staticmethod
4647 def RFolder ():
@@ -50,6 +51,15 @@ def RFolder():
5051
5152 return os .path .abspath (unicode (folder ))
5253
54+ @staticmethod
55+ def RLibs ():
56+ folder = ProcessingConfig .getSetting (RUtils .R_LIBS_USER )
57+ if folder is None :
58+ folder = unicode (os .path .join (userFolder (), 'rlibs' ))
59+ mkdir (folder )
60+
61+ return os .path .abspath (unicode (folder ))
62+
5363 @staticmethod
5464 def RScriptsFolder ():
5565 folder = ProcessingConfig .getSetting (RUtils .RSCRIPTS_FOLDER )
@@ -90,8 +100,9 @@ def executeRAlgorithm(alg, progress):
90100 'BATCH' ,
91101 '--vanilla' ,
92102 RUtils .getRScriptFilename (),
93- RUtils .getConsoleOutputFilename (),
103+ RUtils .getConsoleOutputFilename ()
94104 ]
105+
95106 else :
96107 os .chmod (RUtils .getRScriptFilename (), stat .S_IEXEC | stat .S_IREAD
97108 | stat .S_IWRITE )
You can’t perform that action at this time.
0 commit comments