def test_use_user_library(self):
     """
     Test retrieving/setting the user library setting
     """
     self.assertTrue(RUtils.use_user_library())
     ProcessingConfig.setSettingValue(RUtils.R_USE_USER_LIB, False)
     self.assertFalse(RUtils.use_user_library())
     ProcessingConfig.setSettingValue(RUtils.R_USE_USER_LIB, True)
     self.assertTrue(RUtils.use_user_library())
Beispiel #2
0
    def build_script_header_commands(self, _, __, ___):
        """
        Builds the set of script startup commands for the algorithm
        """
        commands = list()

        # Just use main mirror
        commands.append('options("repos"="{}")'.format(RUtils.package_repo()))

        # Try to install packages if needed
        if RUtils.use_user_library():
            commands.append('.libPaths(\"' +
                            str(RUtils.r_library_folder()).replace('\\', '/') +
                            '\")')

        packages = RUtils.get_required_packages(self.script)
        packages.extend(['rgdal', 'raster'])
        for p in packages:
            commands.append('tryCatch(find.package("' + p +
                            '"), error=function(e) install.packages("' + p +
                            '", dependencies=TRUE))')
        commands.append('library("raster")')
        commands.append('library("rgdal")')

        return commands
    def build_script_header_commands(self, script) -> List[str]:
        """
        Builds the set of script startup commands for the algorithm, based on necessary packages,
        github_install parameter and script analysis.

        :param script: variable self.script from RAlgorithm
        :return: list of str (commands)
        """

        commands = []

        # Just use main mirror
        commands.append(self.set_option_repos(RUtils.package_repo()))

        # Try to install packages if needed
        if RUtils.use_user_library():
            path_to_use = str(RUtils.r_library_folder()).replace('\\', '/')
            commands.append(self.change_libPath(path_to_use))

        packages = self.get_necessary_packages()

        for p in packages:
            commands.append(self.check_package_availability(p))
            commands.append(self.load_package(p))

        if self.install_github:
            for dependency in self.github_dependencies:
                commands.append(self.install_package_github(dependency))

        packages_script = RUtils.get_required_packages(script)

        for p in packages_script:
            commands.append(self.check_package_availability(p))
            commands.append(self.load_package(p))

        return commands