def load(self): """ Called when first loading provider """ ProcessingConfig.settingIcons[self.name()] = self.icon() ProcessingConfig.addSetting( Setting(self.name(), 'ACTIVATE_R', self.tr('Activate'), False)) ProcessingConfig.addSetting( Setting(self.name(), RUtils.RSCRIPTS_FOLDER, self.tr('R scripts folder'), RUtils.default_scripts_folder(), valuetype=Setting.MULTIPLE_FOLDERS)) ProcessingConfig.addSetting( Setting(self.name(), 'ACTIVATE_R', self.tr('Activate'), False)) ProcessingConfig.addSetting( Setting( self.name(), RUtils.R_USE_USER_LIB, self.tr('Use user library folder instead of system libraries'), True)) ProcessingConfig.addSetting( Setting(self.name(), RUtils.R_LIBS_USER, self.tr('User library folder'), RUtils.r_library_folder(), valuetype=Setting.FOLDER)) ProcessingConfig.addSetting( Setting(self.name(), RUtils.R_REPO, self.tr('Package repository'), "http://cran.at.r-project.org/", valuetype=Setting.STRING)) ProcessingConfig.addSetting( Setting(self.name(), RUtils.R_FOLDER, self.tr('R folder'), RUtils.r_binary_folder(), valuetype=Setting.FOLDER)) if RUtils.is_windows(): ProcessingConfig.addSetting( Setting(self.name(), RUtils.R_USE64, self.tr('Use 64 bit version'), False)) ProviderActions.registerProviderActions(self, self.actions) ProviderContextMenuActions.registerProviderContextMenuActions( self.contextMenuActions) ProcessingConfig.readSettings() self.refreshAlgorithms() return True
def unload(self): """ Called when unloading provider """ ProcessingConfig.removeSetting('ACTIVATE_R') ProcessingConfig.removeSetting(RUtils.RSCRIPTS_FOLDER) ProcessingConfig.removeSetting(RUtils.R_LIBS_USER) ProcessingConfig.removeSetting(RUtils.R_FOLDER) if RUtils.is_windows(): ProcessingConfig.removeSetting(RUtils.R_USE64) ProviderActions.deregisterProviderActions(self) ProviderContextMenuActions.deregisterProviderContextMenuActions( self.contextMenuActions)
def processAlgorithm(self, parameters, context, feedback): """ Executes the algorithm """ self.results = {} if RUtils.is_windows(): path = RUtils.r_binary_folder() if path == '': raise QgsProcessingException( self.tr('R folder is not configured.\nPlease configure it ' 'before running R scripts.')) feedback.pushInfo(self.tr('R execution commands')) script_lines = self.build_r_script(parameters, context, feedback) for line in script_lines: feedback.pushCommandInfo(line) output = RUtils.execute_r_algorithm(self, parameters, context, feedback) if self.show_plots: html_filename = self.parameterAsFileOutput(parameters, RAlgorithm.RPLOTS, context) if html_filename: with open(html_filename, 'w') as f: f.write('<html><img src="' + self.plots_filename + '"/></html>') self.results[RAlgorithm.RPLOTS] = html_filename if self.show_console_output: html_filename = self.parameterAsFileOutput( parameters, RAlgorithm.R_CONSOLE_OUTPUT, context) if html_filename: with open(html_filename, 'w') as f: f.write(RUtils.html_formatted_console_output(output)) self.results[RAlgorithm.R_CONSOLE_OUTPUT] = html_filename return self.results
def test_is_windows(self): """ Test is_windows """ self.assertFalse(RUtils.is_windows()) # suck it, Windows users!