예제 #1
0
 def unload(self):
     """
     Called when unloading provider
     """
     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)
예제 #2
0
    def load(self):
        """
        Called when first loading provider
        """
        ProcessingConfig.settingIcons[self.name()] = self.icon()
        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(), 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()
        self.r_version = RUtils.get_r_version()
        return True
예제 #3
0
    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'))

        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="{}"/></html>'.format(
                        QUrl.fromLocalFile(self.plots_filename).toString()))
                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

        if self.save_output_values and self.output_values_filename:
            with open(self.output_values_filename, 'r') as f:
                lines = [line.strip() for line in f]
            # get output values stored into the file
            outputs = self.parse_output_values(iter(lines))
            # merge output values into results
            for k, v in outputs.items():
                if k not in self.results:
                    self.results[k] = v

        return self.results
예제 #4
0
    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="{}"/></html>'.format(
                        QUrl.fromLocalFile(self.plots_filename).toString()))
                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
예제 #5
0
 def test_is_windows(self):
     """
     Test is_windows
     """
     self.assertFalse(RUtils.is_windows())  # suck it, Windows users!