Exemple #1
0
        /// <summary>
        /// Retrieves path to the latest (highest version) R installation
        /// from registry. Typically in the form 'Program Files\R\R-3.2.1'
        /// Selects highest from compatible versions, not just the highest.
        /// </summary>
        public static string GetCompatibleEnginePathFromRegistry(ISupportedRVersionRange svl = null)
        {
            svl = svl ?? new SupportedRVersionRange();
            string[] installedEngines   = GetInstalledEngineVersionsFromRegistry();
            string   highestVersionName = String.Empty;
            Version  highest            = null;

            foreach (string name in installedEngines)
            {
                // Protect from random key name format changes
                if (!String.IsNullOrEmpty(name))
                {
                    string  versionString = ExtractVersionString(name);
                    Version v;
                    if (Version.TryParse(versionString, out v) && svl.IsCompatibleVersion(v))
                    {
                        if (highest != null)
                        {
                            if (v > highest)
                            {
                                highest            = v;
                                highestVersionName = name;
                            }
                        }
                        else
                        {
                            highest            = v;
                            highestVersionName = name;
                        }
                    }
                }
            }

            return(GetRVersionInstallPathFromRegistry(highestVersionName));
        }
Exemple #2
0
        private static string TryFindRInProgramFiles(string folder, ISupportedRVersionRange supportedVersions)
        {
            string         root        = Path.GetPathRoot(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles));
            string         baseRFolder = Path.Combine(root + @"Program Files\", folder);
            List <Version> versions    = new List <Version>();

            try {
                IEnumerable <IFileSystemInfo> directories = FileSystem.GetDirectoryInfo(baseRFolder)
                                                            .EnumerateFileSystemInfos()
                                                            .Where(x => (x.Attributes & FileAttributes.Directory) != 0);
                foreach (IFileSystemInfo fsi in directories)
                {
                    string  subFolderName = fsi.FullName.Substring(baseRFolder.Length + 1);
                    Version v             = GetRVersionFromFolderName(subFolderName);
                    if (supportedVersions.IsCompatibleVersion(v))
                    {
                        versions.Add(v);
                    }
                }
            } catch (IOException) {
                // Don't do anything if there is no RRO installed
            }

            if (versions.Count > 0)
            {
                versions.Sort();
                Version highest = versions[versions.Count - 1];
                return(Path.Combine(baseRFolder, String.Format(CultureInfo.InvariantCulture, "R-{0}.{1}.{2}", highest.Major, highest.Minor, highest.Build)));
            }

            return(string.Empty);
        }
Exemple #3
0
        /// <summary>
        /// Retrieves path to the installed R engine root folder.
        /// First tries user settings, then 64-bit registry.
        /// </summary>
        public static string GetRInstallPath(string basePath, ISupportedRVersionRange svl = null, ICoreShell coreShell = null)
        {
            svl = svl ?? new SupportedRVersionRange();
            // First check if Microsoft R Client was just installed.
            var rClientPath = GetRClientPath();

            if (!string.IsNullOrEmpty(rClientPath) && AskUserSwitchToRClient())
            {
                // Get R Client path
                if (MessageButtons.Yes == coreShell.ShowMessage(Resources.Prompt_MsRClientJustInstalled, MessageButtons.YesNo))
                {
                    return(GetRClientPath());
                }
            }

            if (string.IsNullOrEmpty(basePath) || !FileSystem.DirectoryExists(basePath))
            {
                basePath = GetRPathFromMRS();
                if (string.IsNullOrEmpty(basePath))
                {
                    basePath = GetCompatibleEnginePathFromRegistry(svl);
                }
            }

            return(basePath);
        }
Exemple #4
0
        public IEnumerable <IRInterpreterInfo> GetCompatibleEngines(ISupportedRVersionRange svl = null)
        {
            var interpreters = new List <IRInterpreterInfo>();

            interpreters.AddRange(GetInstalledCranR(svl));
            return(interpreters);
        }
Exemple #5
0
        public IEnumerable <IRInterpreterInfo> GetCompatibleEngines(ISupportedRVersionRange svl = null)
        {
            var packagesInfo = InstalledPackageInfo.GetPackages(_fileSystem);
            var interpreters = new List <IRInterpreterInfo>();

            interpreters.AddRange(GetInstalledMRO(packagesInfo, svl));
            interpreters.AddRange(GetInstalledCranR(packagesInfo, svl));
            return(interpreters);
        }
        /// <summary>
        /// Determines if given version falls into the supported range.
        /// </summary>
        /// <param name="v"></param>
        /// <returns></returns>
        public static bool IsCompatibleVersion(this ISupportedRVersionRange svr, Version v)
        {
            var minVersion = new Version(svr.MinMajorVersion, svr.MinMinorVersion);
            var maxVersion = new Version(svr.MaxMajorVersion, svr.MaxMinorVersion);

            var verMajorMinor = new Version(v.Major, v.Minor);

            return(verMajorMinor >= minVersion && verMajorMinor <= maxVersion);
        }
Exemple #7
0
 /// <summary>
 /// Retrieves path to the all compatible R installations from registry. 
 /// </summary>
 private IEnumerable<IRInterpreterInfo> GetCompatibleEnginesFromRegistry(ISupportedRVersionRange svr) {
     svr = svr ?? new SupportedRVersionRange();
     var engines = GetInstalledEnginesFromRegistry().Where(e => svr.IsCompatibleVersion(e.Version));
     // Remove duplicates (MRC registers under multiple keys)
     var mrc = engines.FirstOrDefault(e => e.Name.Contains("Microsoft"));
     if(mrc != null) {
         var dupes = engines.Where(e => e.InstallPath.EqualsIgnoreCase(mrc.InstallPath)).Except(new IRInterpreterInfo[] { mrc });
         engines = engines.Except(dupes);
     }
     return engines;
 }
Exemple #8
0
        /// <summary>
        /// Retrieves path to the installed R engine binaries folder.
        /// R version is retrieved from settings or, af none is set,
        /// highest version is retrieved from registry.
        /// </summary>
        public static string GetBinariesFolder(string basePath, ISupportedRVersionRange svl, ICoreShell coreShell = null)
        {
            string binFolder   = null;
            string installPath = RInstallation.GetRInstallPath(basePath, svl, coreShell);

            if (!String.IsNullOrEmpty(installPath))
            {
                binFolder = Path.Combine(installPath, @"bin\x64");
            }

            return(binFolder);
        }
Exemple #9
0
        /// <summary>
        /// Retrieves path to the all compatible R installations from registry.
        /// </summary>
        private IEnumerable <IRInterpreterInfo> GetCompatibleEnginesFromRegistry(ISupportedRVersionRange svr)
        {
            svr = svr ?? new SupportedRVersionRange();
            var engines = GetInstalledEnginesFromRegistry().Where(e => svr.IsCompatibleVersion(e.Version));

            // Among duplicates by path take the highest version
            return
                (from e in engines
                 group e by e.InstallPath.TrimTrailingSlash()
                 into g
                 select g.OrderByDescending(e => e.Version).First());
        }
Exemple #10
0
        private IEnumerable <IRInterpreterInfo> GetInstalledCranR(ISupportedRVersionRange svl)
        {
            var rFrameworkPath = Path.Combine("/Library/Frameworks/R.framework/Versions");

            foreach (var path in _fileSystem.GetDirectories(rFrameworkPath))
            {
                var version = VersionFromPath(path, out var versionString);
                if (version != null && svl.IsCompatibleVersion(version))
                {
                    yield return(new RMacInterpreterInfo("R " + versionString, versionString, version, _fileSystem));
                }
            }
        }
Exemple #11
0
 /// <summary>
 /// Retrieves path to the installed R engine root folder.
 /// First tries user settings, then 64-bit registry.
 /// </summary>
 public static string GetRInstallPath(string basePath, ISupportedRVersionRange svl = null)
 {
     svl = svl ?? new SupportedRVersionRange();
     if (string.IsNullOrEmpty(basePath) || !FileSystem.DirectoryExists(basePath))
     {
         basePath = GetRPathFromMRS();
         if (string.IsNullOrEmpty(basePath))
         {
             basePath = GetCompatibleEnginePathFromRegistry(svl);
         }
     }
     return(basePath);
 }
Exemple #12
0
        /// <summary>
        /// Retrieves path to the all compatible R installations from registry.
        /// </summary>
        private IEnumerable <IRInterpreterInfo> GetCompatibleEnginesFromRegistry(ISupportedRVersionRange svr)
        {
            svr = svr ?? new SupportedRVersionRange();
            var engines = GetInstalledEnginesFromRegistry().Where(e => svr.IsCompatibleVersion(e.Version));
            // Remove duplicates (MRC registers under multiple keys)
            var mrc = engines.FirstOrDefault(e => e.Name.Contains("Microsoft"));

            if (mrc != null)
            {
                var dupes = engines.Where(e => e.InstallPath.EqualsIgnoreCase(mrc.InstallPath)).Except(new IRInterpreterInfo[] { mrc });
                engines = engines.Except(dupes);
            }
            return(engines);
        }
Exemple #13
0
        public bool VerifyInstallation(ISupportedRVersionRange svr = null, IServiceContainer services = null)
        {
            var ui = services?.GetService <IUIService>();

            if (_isValid.HasValue)
            {
                return(_isValid.Value);
            }

            _isValid = false;

            svr = svr ?? new SupportedRVersionRange();

            // Normalize path so it points to R root and not to bin or bin\x64
            string rDllPath      = Path.Combine(BinPath, "R.dll");
            string rGraphAppPath = Path.Combine(BinPath, "Rgraphapp.dll");
            string rTermPath     = Path.Combine(BinPath, "RTerm.exe");
            string rScriptPath   = Path.Combine(BinPath, "RScript.exe");
            string rGuiPath      = Path.Combine(BinPath, "RGui.exe");

            try {
                if (_fileSystem.FileExists(rDllPath) && _fileSystem.FileExists(rTermPath) &&
                    _fileSystem.FileExists(rScriptPath) && _fileSystem.FileExists(rGraphAppPath) &&
                    _fileSystem.FileExists(rGuiPath))
                {
                    var fileVersion = GetRVersionFromBinary(_fileSystem, rDllPath);
                    _isValid = IsSameVersion(fileVersion, Version) && svr.IsCompatibleVersion(Version);
                    if (!_isValid.Value)
                    {
                        ui?.ShowMessage(
                            string.Format(CultureInfo.InvariantCulture, Resources.Error_UnsupportedRVersion,
                                          Version.Major, Version.Minor, Version.Build, svr.MinMajorVersion, svr.MinMinorVersion, "*",
                                          svr.MaxMajorVersion, svr.MaxMinorVersion, "*"), MessageButtons.OK);
                    }
                }
                else
                {
                    ui?.ShowMessage(string.Format(CultureInfo.InvariantCulture, Resources.Error_CannotFindRBinariesFormat, InstallPath), MessageButtons.OK);
                }
            } catch (Exception ex) when(ex is IOException || ex is ArgumentException || ex is UnauthorizedAccessException)
            {
                ui?.ShowErrorMessage(
                    string.Format(CultureInfo.InvariantCulture, Resources.Error_ExceptionAccessingPath, InstallPath, ex.Message));
            }

            return(_isValid.Value);
        }
Exemple #14
0
        public bool VerifyInstallation(ISupportedRVersionRange svr = null, IServiceContainer services = null)
        {
            var ui = services?.GetService <IUIService>();

            if (_isValid.HasValue)
            {
                return(_isValid.Value);
            }

            _isValid = false;

            svr = svr ?? new SupportedRVersionRange();
            string libRPath = Path.Combine(BinPath, "libR.so");

            try {
                if (_fileSystem.DirectoryExists(InstallPath) && _fileSystem.DirectoryExists(BinPath) &&
                    _fileSystem.FileExists(libRPath))
                {
                    if (Version != null)
                    {
                        _isValid = svr.IsCompatibleVersion(Version);
                        if (!_isValid.Value)
                        {
                            ui?.ShowMessage(
                                Resources.Error_UnsupportedRVersion.FormatInvariant(
                                    Version.Major, Version.Minor, Version.Build, svr.MinMajorVersion, svr.MinMinorVersion, "*",
                                    svr.MaxMajorVersion, svr.MaxMinorVersion, "*"), MessageButtons.OK);
                        }
                    }
                    else
                    {
                        // In linux there is no direct way to get version from binary. So assume valid version for a user provided
                        // interpreter path.
                        _isValid = true;
                    }
                }
                else
                {
                    ui?.ShowMessage(Resources.Error_CannotFindRBinariesFormat.FormatInvariant(InstallPath), MessageButtons.OK);
                }
            } catch (Exception ex) when(ex is IOException || ex is ArgumentException || ex is UnauthorizedAccessException)
            {
                ui?.ShowErrorMessage(Resources.Error_ExceptionAccessingPath.FormatInvariant(InstallPath, ex.Message));
            }

            return(_isValid.Value);
        }
Exemple #15
0
        /// <summary>
        /// Retrieves path to the latest (highest version) R installation
        /// from registry. Typically in the form 'Program Files\R\R-3.2.1'
        /// Selects highest from compatible versions, not just the highest.
        /// </summary>
        public IEnumerable <IRInterpreterInfo> GetCompatibleEngines(ISupportedRVersionRange svl = null)
        {
            var list = new List <IRInterpreterInfo>();

            // Get MRC from SQL
            var mrc = SqlRClientInstallation.GetMicrosoftRClientInfo(_registry, _fileSystem);

            if (mrc != null)
            {
                list.Add(mrc);
            }

            var engines = GetCompatibleEnginesFromRegistry(svl);

            engines = engines.Where(e => e.VerifyInstallation(svl, _fileSystem))
                      .OrderBy(e => e.Version);

            if (mrc == null)
            {
                // If MRC didn't come with SQL, try finding one in the R engines
                mrc = engines.FirstOrDefault(e => e.Name.Contains("Microsoft R"));
                if (mrc != null)
                {
                    list.Add(mrc);
                }
            }

            if (mrc != null)
            {
                // Remove MRC and its duplicates
                engines = engines.Where(e => !e.InstallPath.PathEquals(mrc.InstallPath));
            }

            list.AddRange(engines);
            if (list.Count == 0)
            {
                var e = TryFindRInProgramFiles(svl);
                if (e != null)
                {
                    list.Add(e);
                }
            }

            return(list);
        }
Exemple #16
0
        private IRInterpreterInfo TryFindRInProgramFiles(ISupportedRVersionRange supportedVersions)
        {
            // Force 64-bit PF
            var programFiles = Environment.GetEnvironmentVariable("ProgramW6432");
            var baseRFolder  = Path.Combine(programFiles, @"R");
            var versions     = new List <Version>();

            try {
                if (_fileSystem.DirectoryExists(baseRFolder))
                {
                    IEnumerable <IFileSystemInfo> directories = _fileSystem.GetDirectoryInfo(baseRFolder)
                                                                .EnumerateFileSystemInfos()
                                                                .Where(x => (x.Attributes & FileAttributes.Directory) != 0);
                    foreach (IFileSystemInfo fsi in directories)
                    {
                        string  subFolderName = fsi.FullName.Substring(baseRFolder.Length + 1);
                        Version v             = GetRVersionFromFolderName(subFolderName);
                        if (supportedVersions.IsCompatibleVersion(v))
                        {
                            versions.Add(v);
                        }
                    }
                }
            } catch (IOException) {
                // Don't do anything if there is no RRO installed
            }

            if (versions.Count > 0)
            {
                versions.Sort();
                Version highest = versions[versions.Count - 1];
                var     name    = string.Format(CultureInfo.InvariantCulture, "R-{0}.{1}.{2}", highest.Major, highest.Minor, highest.Build);
                var     path    = Path.Combine(baseRFolder, name);
                var     ri      = CreateInfo(name, path);
                if (ri.VerifyInstallation(supportedVersions))
                {
                    return(ri);
                }
            }

            return(null);
        }
Exemple #17
0
        public static bool VerifyRIsInstalled(ICoreShell coreShell, ISupportedRVersionRange svl, string path, bool showErrors = true)
        {
            svl = svl ?? new SupportedRVersionRange();
            var data = RInstallation.GetInstallationData(path, svl, coreShell);

            if (data.Status == RInstallStatus.OK)
            {
                return(true);
            }

            if (showErrors)
            {
                if (ShowMessage(coreShell, data, svl) == MessageButtons.Yes)
                {
                    var installer = coreShell.ExportProvider.GetExportedValue <IMicrosoftRClientInstaller>();
                    installer.LaunchRClientSetup(coreShell);
                }
            }

            return(false);
        }
Exemple #18
0
        public IEnumerable <IRInterpreterInfo> GetCompatibleEngines(ISupportedRVersionRange svl = null)
        {
            var list = new List <IRInterpreterInfo>();

            var engines = GetCompatibleEnginesFromRegistry(svl);

            engines = engines.Where(e => e.VerifyInstallation(svl))
                      .OrderBy(e => e.Version);

            list.AddRange(engines);
            if (list.Count == 0)
            {
                var e = TryFindRInProgramFiles(svl);
                if (e != null)
                {
                    list.Add(e);
                }
            }

            return(list);
        }
Exemple #19
0
        public bool VerifyInstallation(ISupportedRVersionRange svr = null, IFileSystem fs = null, ICoreShell coreShell = null) {
            if (_isValid.HasValue) {
                return _isValid.Value;
            }

            _isValid = false;

            svr = svr ?? new SupportedRVersionRange();
            fs = fs ?? new FileSystem();

            // Normalize path so it points to R root and not to bin or bin\x64
            string rDllPath = Path.Combine(BinPath, "R.dll");
            string rGraphAppPath = Path.Combine(BinPath, "Rgraphapp.dll");
            string rTermPath = Path.Combine(BinPath, "RTerm.exe");
            string rScriptPath = Path.Combine(BinPath, "RScript.exe");
            string rGuiPath = Path.Combine(BinPath, "RGui.exe");

            try {
                if (fs.FileExists(rDllPath) && fs.FileExists(rTermPath) &&
                    fs.FileExists(rScriptPath) && fs.FileExists(rGraphAppPath) &&
                    fs.FileExists(rGuiPath)) {

                    var fileVersion = GetRVersionFromBinary(fs, rDllPath);
                    _isValid = IsSameVersion(fileVersion, Version) && svr.IsCompatibleVersion(Version);
                    if (!_isValid.Value) {
                        coreShell?.ShowMessage(
                            string.Format(CultureInfo.InvariantCulture, Resources.Error_UnsupportedRVersion,
                            Version.Major, Version.Minor, Version.Build, svr.MinMajorVersion, svr.MinMinorVersion, "*",
                            svr.MaxMajorVersion, svr.MaxMinorVersion, "*"), MessageButtons.OK);
                    }
                } else {
                    coreShell?.ShowMessage(string.Format(CultureInfo.InvariantCulture, Resources.Error_CannotFindRBinariesFormat, InstallPath), MessageButtons.OK);
                }
            } catch (Exception ex) when (ex is IOException || ex is ArgumentException || ex is UnauthorizedAccessException) {
                coreShell?.ShowErrorMessage(
                    string.Format(CultureInfo.InvariantCulture, Resources.Error_ExceptionAccessingPath, InstallPath, ex.Message));
            }

            return _isValid.Value;
        }
Exemple #20
0
        /// <summary>
        /// Retrieves path to the latest (highest version) R installation
        /// from registry. Typically in the form 'Program Files\R\R-3.2.1'
        /// Selects highest from compatible versions, not just the highest.
        /// </summary>
        public IEnumerable<IRInterpreterInfo> GetCompatibleEngines(ISupportedRVersionRange svl = null) {
            var list = new List<IRInterpreterInfo>();

            // Get MRC from SQL
            var mrc = SqlRClientInstallation.GetMicrosoftRClientInfo(_registry, _fileSystem);
            if (mrc != null) {
                list.Add(mrc);
            }

            var engines = GetCompatibleEnginesFromRegistry(svl);
            engines = engines.Where(e => e.VerifyInstallation(svl, _fileSystem))
                             .OrderBy(e => e.Version);

            if (mrc == null) {
                // If MRC didn't come with SQL, try finding one in the R engines
                mrc = engines.FirstOrDefault(e => e.Name.Contains("Microsoft R"));
                if (mrc != null) {
                    list.Add(mrc);
                }
            }

            if (mrc != null) { 
                // Remove MRC and its duplicates
                engines = engines.Where(e => !e.InstallPath.PathEquals(mrc.InstallPath));
            }

            list.AddRange(engines);
            if (list.Count == 0) {
                var e = TryFindRInProgramFiles(svl);
                if (e != null) {
                    list.Add(e);
                }
            }

            return list;
        }
Exemple #21
0
        private IEnumerable <IRInterpreterInfo> GetInstalledMRO(IEnumerable <InstalledPackageInfo> packagesInfo, ISupportedRVersionRange svl)
        {
            var selectedPackages = packagesInfo.Where(p => p.PackageName.StartsWithIgnoreCase("microsoft-r-open-mro") && svl.IsCompatibleVersion(p.GetVersion()));

            foreach (var package in selectedPackages)
            {
                yield return(RInterpreterInfo.CreateFromPackage(package, "Microsoft R Open", _fileSystem));
            }
        }
        private static MessageButtons ShowMessage(ICoreShell coreShell, RInstallData data, ISupportedRVersionRange svl)
        {
            Debug.Assert(data.Status != RInstallStatus.OK);

            switch (data.Status)
            {
            case RInstallStatus.UnsupportedVersion:
                return(coreShell.ShowMessage(
                           string.Format(CultureInfo.InvariantCulture, Resources.Error_UnsupportedRVersion,
                                         data.Version.Major, data.Version.Minor, data.Version.Build,
                                         svl.MinMajorVersion, svl.MinMinorVersion, "*",
                                         svl.MaxMajorVersion, svl.MaxMinorVersion, "*",
                                         Environment.NewLine + Environment.NewLine),
                           MessageButtons.YesNo));

            case RInstallStatus.ExceptionAccessingPath:
                coreShell.ShowErrorMessage(
                    string.Format(CultureInfo.InvariantCulture, Resources.Error_ExceptionAccessingPath,
                                  data.Path, data.Exception.Message));
                return(MessageButtons.OK);

            case RInstallStatus.NoRBinaries:
                return(coreShell.ShowMessage(
                           string.Format(CultureInfo.InvariantCulture, Resources.Error_CannotFindRBinariesFormat,
                                         data.Path, Environment.NewLine + Environment.NewLine, Environment.NewLine),
                           MessageButtons.YesNo));

            case RInstallStatus.PathNotSpecified:
                return(coreShell.ShowMessage(string.Format(CultureInfo.InvariantCulture,
                                                           Resources.Error_UnableToFindR, Environment.NewLine + Environment.NewLine), MessageButtons.YesNo));
            }
            return(MessageButtons.OK);
        }
        public static bool VerifyRIsInstalled(this RInstallation rInstallation, ICoreShell coreShell, ISupportedRVersionRange svl, string path, bool showErrors = true)
        {
            svl = svl ?? new SupportedRVersionRange();
            var data = rInstallation.GetInstallationData(path, svl);

            if (data.Status == RInstallStatus.OK)
            {
                return(true);
            }

            if (showErrors)
            {
                if (ShowMessage(coreShell, data, svl) == MessageButtons.Yes)
                {
                    coreShell.TelemetryService.ReportEvent(TelemetryArea.Configuration, MrcTelemetryEvents.RClientInstallPrompt);
                    var installer = coreShell.ExportProvider.GetExportedValue <IMicrosoftRClientInstaller>();
                    installer.LaunchRClientSetup(coreShell);
                }
            }

            return(false);
        }
 protected RInstallationService() {
     var a = Environment.GetEnvironmentVariable("LS_HOST_PROCESS_ARCHITECTURE");
     Architecture = string.IsNullOrWhiteSpace(a) ? ArchitectureString.X64 : a;
     SupportedVersions = new SupportedRVersionRange(3, 2, 4, 9);
 }
Exemple #25
0
        private IEnumerable <IRInterpreterInfo> GetInstalledMRO(IEnumerable <InstalledPackageInfo> packagesInfo, ISupportedRVersionRange svl)
        {
            var list             = new List <IRInterpreterInfo>();
            var selectedPackages = packagesInfo.Where(p => p.PackageName.StartsWithIgnoreCase("microsoft-r-open-mro") && svl.IsCompatibleVersion(p.GetVersion()));

            foreach (var package in selectedPackages)
            {
                var    files        = package.GetPackageFiles(_fileSystem);
                string rInstallPath = GetRInstallPath(files, _fileSystem);
                list.Add(new RInterpreterInfo($"Microsoft R Open '{package.Version}'", rInstallPath, package.Version, package.GetVersion(), _fileSystem));
            }

            return(list);
        }
Exemple #26
0
        private IRInterpreterInfo TryFindRInProgramFiles(ISupportedRVersionRange supportedVersions) {
            // Force 64-bit PF
            var programFiles = Environment.GetEnvironmentVariable("ProgramW6432");
            var baseRFolder = Path.Combine(programFiles, @"R");
            var versions = new List<Version>();
            try {
                if (_fileSystem.DirectoryExists(baseRFolder)) {
                    IEnumerable<IFileSystemInfo> directories = _fileSystem.GetDirectoryInfo(baseRFolder)
                                                                    .EnumerateFileSystemInfos()
                                                                    .Where(x => (x.Attributes & FileAttributes.Directory) != 0);
                    foreach (IFileSystemInfo fsi in directories) {
                        string subFolderName = fsi.FullName.Substring(baseRFolder.Length + 1);
                        Version v = GetRVersionFromFolderName(subFolderName);
                        if (supportedVersions.IsCompatibleVersion(v)) {
                            versions.Add(v);
                        }
                    }
                }
            } catch (IOException) {
                // Don't do anything if there is no RRO installed
            }

            if (versions.Count > 0) {
                versions.Sort();
                Version highest = versions[versions.Count - 1];
                var name = string.Format(CultureInfo.InvariantCulture, "R-{0}.{1}.{2}", highest.Major, highest.Minor, highest.Build);
                var path = Path.Combine(baseRFolder, name);
                var ri = new RInterpreterInfo(name, path);
                if (ri.VerifyInstallation(supportedVersions)) {
                    return ri;
                }
            }

            return null;
        }
Exemple #27
0
        private IEnumerable <IRInterpreterInfo> GetInstalledCranR(IEnumerable <InstalledPackageInfo> packagesInfo, ISupportedRVersionRange svl)
        {
            var list             = new List <IRInterpreterInfo>();
            var selectedPackages = packagesInfo.Where(p => p.PackageName.EqualsIgnoreCase("r-base-core") && svl.IsCompatibleVersion(p.GetVersion()));

            foreach (var package in selectedPackages)
            {
                var    files        = package.GetPackageFiles(_fileSystem);
                string rInstallPath = GetRInstallPath(files, _fileSystem);
                list.Add(new RInterpreterInfo($"R '{package.Version}'", rInstallPath, package.Version, package.GetVersion(), _fileSystem));
            }

            return(list);
        }
Exemple #28
0
        private IEnumerable <IRInterpreterInfo> GetInstalledCranR(IEnumerable <InstalledPackageInfo> packagesInfo, ISupportedRVersionRange svl)
        {
            var selectedPackages = packagesInfo.Where(p => p.PackageName.EqualsIgnoreCase("r-base-core") && svl.IsCompatibleVersion(p.GetVersion()));

            foreach (var package in selectedPackages)
            {
                yield return(RInterpreterInfo.CreateFromPackage(package, "CRAN R", _fileSystem));
            }
        }
Exemple #29
0
        /// <summary>
        /// Tries to determine R installation information. If user-specified path
        /// is supplied, it is used. If not, registry is used. If nothing is found
        /// in the registry, makes attempt to find compatible 64-bit installation
        /// of MRO, RRO or R (in this order) in Program Files folder
        /// </summary>
        /// <param name="basePath">Path as specified by the user settings</param>
        /// <returns></returns>
        public static RInstallData GetInstallationData(
            string basePath,
            ISupportedRVersionRange svl,
            ICoreShell coreShell = null)
        {
            string path = GetRInstallPath(basePath, svl, coreShell);

            // If nothing is found, look into the file system
            if (string.IsNullOrEmpty(path))
            {
                foreach (var f in rFolders)
                {
                    path = TryFindRInProgramFiles(f, svl);
                    if (!string.IsNullOrEmpty(path))
                    {
                        break;
                    }
                }
            }

            // Still nothing? Fail, caller will typically display an error message.
            if (string.IsNullOrEmpty(path))
            {
                return(new RInstallData()
                {
                    Status = RInstallStatus.PathNotSpecified
                });
            }

            // Now verify if files do exist and are of the correct version.
            // There may be cases when R was not fully uninstalled or when
            // version claimed in the registry is not what is really in files.
            RInstallData data = new RInstallData()
            {
                Status = RInstallStatus.OK, Path = path
            };

            // Normalize path so it points to R root and not to bin or bin\x64
            path = NormalizeRPath(path);
            try {
                string rDirectory = Path.Combine(path, @"bin\x64");
                data.BinPath = rDirectory;

                string rDllPath      = Path.Combine(rDirectory, "R.dll");
                string rGraphAppPath = Path.Combine(rDirectory, "Rgraphapp.dll");
                string rTermPath     = Path.Combine(rDirectory, "RTerm.exe");
                string rScriptPath   = Path.Combine(rDirectory, "RScript.exe");
                string rGuiPath      = Path.Combine(rDirectory, "RGui.exe");

                if (FileSystem.FileExists(rDllPath) && FileSystem.FileExists(rTermPath) &&
                    FileSystem.FileExists(rScriptPath) && FileSystem.FileExists(rGraphAppPath) &&
                    FileSystem.FileExists(rGuiPath))
                {
                    IFileVersionInfo fvi = FileSystem.GetVersionInfo(rDllPath);
                    int minor, revision;

                    GetRVersionPartsFromFileMinorVersion(fvi.FileMinorPart, out minor, out revision);
                    data.Version = new Version(fvi.FileMajorPart, minor, revision);

                    if (!svl.IsCompatibleVersion(data.Version))
                    {
                        data.Status = RInstallStatus.UnsupportedVersion;
                    }
                }
                else
                {
                    data.Status = RInstallStatus.NoRBinaries;
                }
            } catch (ArgumentException aex) {
                data.Status    = RInstallStatus.ExceptionAccessingPath;
                data.Exception = aex;
            } catch (IOException ioex) {
                data.Status    = RInstallStatus.ExceptionAccessingPath;
                data.Exception = ioex;
            }

            return(data);
        }