//Install Package from CRAN.
        public UAReturn InstallPackageFromCRAN(string packagename)
        {
            UAReturn result = new UAReturn()
            {
                Success = false
            };
            string command = string.Empty;
            string retmsg  = string.Empty;

            string[] pkgs = packagename.Split(',');

            //Get R User lib from config
            //R standard rule: If lib is missing in install.packages(), defaults to the first element of .libPaths().
            //so better pass lib parameter so that user can install his/her own R packages in user personal library.
            string userRlibConfig = confService.GetConfigValueForKey("userRlib");

            result = IsUserRlibValid(userRlibConfig);
            if (!result.Success)
            {
                return(result);
            }

            string packagenames = GetCommaSeparatedWithSingleQuotes(pkgs);

            if (packagenames == null)//bad string
            {
                result.CommandString = packagename;
                retmsg = " " + BSky.GlobalResources.Properties.Resources.MultiRPkgInstallMsg;
            }
            else
            {
                foreach (string pkgnam in pkgs)//uninstall package(s)
                {
                    //UAReturn result = new UAReturn() { Success = false };
                    if (_dispatcher.IsLoaded(pkgnam)) // if package is already loaded. Unload and uninstall it
                    {
                        UnLoadPackage(pkgnam);
                        UninstallPackage(pkgnam);
                    }
                }
                string CranUrl = "http://cran.us.r-project.org";
                command = string.Format("install.packages(c({0}), lib='" + userRlibConfig + "')", packagenames);
                retmsg  = _dispatcher.EvaluateToString(command);
            }

            _journal.WriteLine(command);
            result.CommandString = command;
            result.Error         = retmsg;
            if (retmsg.Contains("Check Command.") || retmsg.ToLower().Contains("error") || retmsg.ToLower().Contains("warning"))
            {
                result.Success = false;
            }
            else
            {
                result.Success = true;
            }
            return(result);
        }
        //Install Package from CRAN.
        public UAReturn InstallPackageFromCRAN(string packagename)
        {
            UAReturn result = new UAReturn()
            {
                Success = false
            };
            string command = string.Empty;
            string retmsg  = string.Empty;

            string[] pkgs         = packagename.Split(',');
            string   packagenames = GetCommaSeparatedWithSingleQuotes(pkgs);

            if (packagenames == null)//bad string
            {
                result.CommandString = packagename;
                retmsg = " Mulitple packages must be comma separated and no quotes should be used.";
            }
            else
            {
                foreach (string pkgnam in pkgs)//uninstall package(s)
                {
                    //UAReturn result = new UAReturn() { Success = false };
                    if (_dispatcher.IsLoaded(pkgnam)) // if package is already loaded. Unload and uninstall it
                    {
                        UnLoadPackage(pkgnam);
                        UninstallPackage(pkgnam);
                    }
                }
                string CranUrl = "http://cran.us.r-project.org";
                //string command = "utils:::menuInstallPkgs()";
                command = string.Format("install.packages(c({0}))", packagenames);
                //string command = string.Format("install.packages('{0}', repos='{1}')", packagename, CranUrl);
                retmsg = _dispatcher.EvaluateToString(command);
            }

            _journal.WriteLine(command);
            result.CommandString = command;
            result.Error         = retmsg;
            if (retmsg.Contains("Check Command.") || retmsg.ToLower().Contains("error") || retmsg.ToLower().Contains("warning"))
            {
                result.Success = false;
            }
            else
            {
                result.Success = true;
            }

            //LoadPackage(packagename); // Normally, when we install package, it should also be loaded. Can also be done outside.
            return(result);
        }
Exemplo n.º 3
0
        //Install Package from CRAN.
        public UAReturn InstallPackageFromCRAN(string packagename)
        {
            UAReturn result = new UAReturn()
            {
                Success = false
            };
            string command = string.Empty;
            string retmsg  = string.Empty;

            string[] pkgs         = packagename.Split(',');
            string   packagenames = GetCommaSeparatedWithSingleQuotes(pkgs);

            if (packagenames == null)//bad string
            {
                result.CommandString = packagename;
                retmsg = " " + BSky.GlobalResources.Properties.Resources.MultiRPkgInstallMsg;
            }
            else
            {
                foreach (string pkgnam in pkgs)//uninstall package(s)
                {
                    //UAReturn result = new UAReturn() { Success = false };
                    if (_dispatcher.IsLoaded(pkgnam)) // if package is already loaded. Unload and uninstall it
                    {
                        UnLoadPackage(pkgnam);
                        UninstallPackage(pkgnam);
                    }
                }
                string CranUrl = "http://cran.us.r-project.org";
                command = string.Format("install.packages(c({0}))", packagenames);
                retmsg  = _dispatcher.EvaluateToString(command);
            }

            _journal.WriteLine(command);
            result.CommandString = command;
            result.Error         = retmsg;
            if (retmsg.Contains("Check Command.") || retmsg.ToLower().Contains("error") || retmsg.ToLower().Contains("warning"))
            {
                result.Success = false;
            }
            else
            {
                result.Success = true;
            }
            return(result);
        }