예제 #1
0
        /// <summary>
        /// Executes command line for any R binary with arguments
        /// </summary>
        public static RCommand ExecuteAsync(string executable, string arguments, IActionLog log, string rBasePath)
        {
            RCommand command = new RCommand(log);

            command.SendCommandAsync(rBasePath, executable, arguments);
            return(command);
        }
예제 #2
0
        public static bool IsInstalled(string packageName, int msTimeout, string rBasePath)
        {
            string          expression = "installed.packages()";
            IActionLinesLog log        = new LinesLog(NullLogWriter.Instance);

            bool result = RCommand.ExecuteRExpression(expression, log, msTimeout, rBasePath);

            if (result)
            {
                // stdout is list of packages
                // abind "abind" "C:/Users/[USER_NAME]/Documents/R/win-library/3.2" "1.4-3"   NA
                return(FindPackageName(packageName, log.Lines));
            }

            return(false);
        }
예제 #3
0
 /// <summary>
 /// Executes command line for any R binary with arguments 
 /// </summary>
 public static RCommand ExecuteAsync(string executable, string arguments, IActionLog log, string rBasePath) {
     RCommand command = new RCommand(log);
     command.SendCommandAsync(rBasePath, executable, arguments);
     return command;
 }
예제 #4
0
        public override CommandResult Invoke(Guid group, int id, object inputArg, ref object outputArg) {
            if (!TaskAvailable()) {
                return CommandResult.Disabled;
            }

            IMarkdownFlavorPublishHandler flavorHandler = GetFlavorHandler(TextView.TextBuffer);
            if (flavorHandler != null) {
                if (!InstallPackages.IsInstalled(flavorHandler.RequiredPackageName, 5000, RToolsSettings.Current.RBasePath)) {
                    VsAppShell.Current.ShowErrorMessage(string.Format(CultureInfo.InvariantCulture, Resources.Error_PackageMissing, flavorHandler.RequiredPackageName));
                    return CommandResult.Disabled;
                }

                // Save the file
                TextView.TextBuffer.Save();
                var inputFilePath = TextView.TextBuffer.GetFilePath();

                var buffer = new StringBuilder(NativeMethods.MAX_PATH);
                NativeMethods.GetShortPathName(inputFilePath, buffer, NativeMethods.MAX_PATH);

                inputFilePath = buffer.ToString();
                _outputFilePath = Path.ChangeExtension(inputFilePath, FileExtension);

                try {
                    File.Delete(_outputFilePath);
                } catch (IOException ex) {
                    PublishLog.Current.WriteFormatAsync(MessageCategory.Error, Resources.Error_CannotDeleteFile, _outputFilePath, ex.Message);
                    return CommandResult.Executed;
                }

                inputFilePath = inputFilePath.Replace('\\', '/');
                string outputFilePath = _outputFilePath.Replace('\\', '/');

                string arguments = flavorHandler.GetCommandLine(inputFilePath, outputFilePath, Format);

                _lastCommand = RCommand.ExecuteRExpressionAsync(arguments, PublishLog.Current, RToolsSettings.Current.RBasePath);
                _lastCommand.Task.ContinueWith((Task t) => LaunchViewer(t));
            }
            return CommandResult.Executed;
        }
예제 #5
0
 /// <summary>
 /// Asynchronously install one R packages with dependencies
 /// </summary>
 public static RCommand Install(string packageName, IActionLog log, string rBasePath)
 {
     return(RCommand.ExecuteAsync("INSTALL " + packageName, log, rBasePath));
 }
예제 #6
0
        /// <summary>
        /// Executes 'RScript --vanilla --slave -e' with the supplied expression
        /// </summary>
        /// <param name="msTimeout"></param>
        /// <returns>Standard output produced by RScript.exe</returns>
        public static bool ExecuteRExpression(string expression, IActionLog log, int msTimeout, string rBasePath)
        {
            RCommand command = ExecuteRExpressionAsync(expression, log, rBasePath);

            return(command.Task.Wait(msTimeout));
        }