Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #2028 from ninsbl/master
Provide option for R_LIBS_USER in Processing
  • Loading branch information
volaya committed May 6, 2015
2 parents c4eb1fb + 70d3907 commit e58e8ac
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
2 changes: 2 additions & 0 deletions python/plugins/processing/algs/r/RAlgorithm.py
Expand Up @@ -285,6 +285,8 @@ def getImportCommands(self):
commands.append('options("repos"="http://cran.at.r-project.org/")')

# Try to install packages if needed
if isWindows():
commands.append('.libPaths(\"' + str(RUtils.RLibs()).replace('\\','/') + '\")')
packages = RUtils.getRequiredPackages(self.script)
packages.extend(['rgdal', 'raster'])
for p in packages:
Expand Down
4 changes: 4 additions & 0 deletions python/plugins/processing/algs/r/RAlgorithmProvider.py
Expand Up @@ -61,6 +61,9 @@ def initializeSettings(self):
ProcessingConfig.addSetting(Setting(
self.getDescription(),
RUtils.R_FOLDER, self.tr('R folder'), RUtils.RFolder()))
ProcessingConfig.addSetting(Setting(
self.getDescription(),
RUtils.R_LIBS_USER, self.tr('R user library folder'), RUtils.RLibs()))
ProcessingConfig.addSetting(Setting(
self.getDescription(),
RUtils.R_USE64, self.tr('Use 64 bit version'), False))
Expand All @@ -70,6 +73,7 @@ def unload(self):
ProcessingConfig.removeSetting(RUtils.RSCRIPTS_FOLDER)
if isWindows():
ProcessingConfig.removeSetting(RUtils.R_FOLDER)
ProcessingConfig.removeSetting(RUtils.R_LIBS_USER)
ProcessingConfig.removeSetting(RUtils.R_USE64)

def getIcon(self):
Expand Down
13 changes: 12 additions & 1 deletion python/plugins/processing/algs/r/RUtils.py
Expand Up @@ -41,6 +41,7 @@ class RUtils:
RSCRIPTS_FOLDER = 'R_SCRIPTS_FOLDER'
R_FOLDER = 'R_FOLDER'
R_USE64 = 'R_USE64'
R_LIBS_USER = 'R_LIBS_USER'

@staticmethod
def RFolder():
Expand All @@ -50,6 +51,15 @@ def RFolder():

return os.path.abspath(unicode(folder))

@staticmethod
def RLibs():
folder = ProcessingConfig.getSetting(RUtils.R_LIBS_USER)
if folder is None:
folder = unicode(os.path.join(userFolder(), 'rlibs'))
mkdir(folder)

return os.path.abspath(unicode(folder))

@staticmethod
def RScriptsFolder():
folder = ProcessingConfig.getSetting(RUtils.RSCRIPTS_FOLDER)
Expand Down Expand Up @@ -90,8 +100,9 @@ def executeRAlgorithm(alg, progress):
'BATCH',
'--vanilla',
RUtils.getRScriptFilename(),
RUtils.getConsoleOutputFilename(),
RUtils.getConsoleOutputFilename()
]

else:
os.chmod(RUtils.getRScriptFilename(), stat.S_IEXEC | stat.S_IREAD
| stat.S_IWRITE)
Expand Down

0 comments on commit e58e8ac

Please sign in to comment.