Ejemplo n.º 1
0
        public static Task PreviousPlotAsync(this IRExpressionEvaluator evaluation, Guid deviceId)
        {
            Debug.Assert(deviceId != Guid.Empty);
            var script = $"rtvs:::graphics.ide.previousplot({deviceId.ToString().ToRStringLiteral()})\n";

            return(evaluation.ExecuteAsync(script));
        }
Ejemplo n.º 2
0
        public static Task ResizePlotAsync(this IRExpressionEvaluator evaluation, Guid deviceId, int width, int height, int resolution)
        {
            Debug.Assert(deviceId != Guid.Empty);
            var script = Invariant($"rtvs:::graphics.ide.resize({deviceId.ToString().ToRStringLiteral()}, {width}, {height}, {resolution})\n");

            return(evaluation.ExecuteAsync(script));
        }
Ejemplo n.º 3
0
 public static Task CopyPlotAsync(this IRExpressionEvaluator evaluation, Guid sourceDeviceId, Guid sourcePlotId, Guid targetDeviceId) {
     Debug.Assert(sourceDeviceId != Guid.Empty);
     Debug.Assert(sourcePlotId != Guid.Empty);
     Debug.Assert(targetDeviceId != Guid.Empty);
     var script = Invariant($"rtvs:::graphics.ide.copyplot({sourceDeviceId.ToString().ToRStringLiteral()}, {sourcePlotId.ToString().ToRStringLiteral()}, {targetDeviceId.ToString().ToRStringLiteral()})\n");
     return evaluation.ExecuteAsync(script);
 }
Ejemplo n.º 4
0
 public static Task SetCodePageAsync(this IRExpressionEvaluator evaluation, int codePage, CancellationToken cancellationToken = default(CancellationToken)) {
     if (codePage == 0) {
         codePage = NativeMethods.GetOEMCP();
     }
     var script = Invariant($"Sys.setlocale('LC_CTYPE', '.{codePage}')");
     return evaluation.ExecuteAsync(script, cancellationToken);
 }
Ejemplo n.º 5
0
        public static Task ClearPlotHistoryAsync(this IRExpressionEvaluator evaluation, Guid deviceId)
        {
            Debug.Assert(deviceId != Guid.Empty);
            var script = Invariant($"rtvs:::graphics.ide.clearplots({deviceId.ToString().ToRStringLiteral()})\n");

            return(evaluation.ExecuteAsync(script));
        }
Ejemplo n.º 6
0
        public static Task RemoveCurrentPlotAsync(this IRExpressionEvaluator evaluation, Guid deviceId, Guid plotId)
        {
            Debug.Assert(deviceId != Guid.Empty);
            Debug.Assert(plotId != Guid.Empty);
            var script = Invariant($"rtvs:::graphics.ide.removeplot({deviceId.ToString().ToRStringLiteral()}, {plotId.ToString().ToRStringLiteral()})\n");

            return(evaluation.ExecuteAsync(script));
        }
Ejemplo n.º 7
0
        public static Task OverrideFunctionAsync(this IRExpressionEvaluator evaluation, string name, string ns)
        {
            name = name.ToRStringLiteral();
            ns   = ns.ToRStringLiteral();
            var script = Invariant($"utils::assignInNamespace({name}, rtvs:::{name}, {ns})");

            return(evaluation.ExecuteAsync(script));
        }
Ejemplo n.º 8
0
        public static Task SetVsGraphicsDeviceAsync(this IRExpressionEvaluator evaluation) {
            var script = @"
attach(as.environment(list(ide = function() { rtvs:::graphics.ide.new() })), name='rtvs::graphics::ide')
options(device='ide')
grDevices::deviceIsInteractive('ide')
";
            return evaluation.ExecuteAsync(script);
        }
Ejemplo n.º 9
0
        public static Task SetROptionsAsync(this IRExpressionEvaluator evaluation) {
            var script =
@"options(help_type = 'html')
  options(browser = rtvs:::open_url)
  options(pager = rtvs:::show_file)
";
            return evaluation.ExecuteAsync(script);
        }
Ejemplo n.º 10
0
        public static Task SetLocalLibsAsync(IRExpressionEvaluator eval, params string[] libPaths) {
            foreach (var libPath in libPaths.Where(libPath => !Directory.Exists(libPath))) {
                Directory.CreateDirectory(libPath);
            }

            var paths = string.Join(",", libPaths.Select(p => p.ToRPath().ToRStringLiteral()));
            var code = $".libPaths(c({paths}))";
            return eval.ExecuteAsync(code);
        }
Ejemplo n.º 11
0
        public static Task SetCodePageAsync(this IRExpressionEvaluator evaluation, int codePage)
        {
            if (codePage == 0)
            {
                codePage = NativeMethods.GetOEMCP();
            }
            var script = Invariant($"Sys.setlocale('LC_CTYPE', '.{codePage}')");

            return(evaluation.ExecuteAsync(script));
        }
Ejemplo n.º 12
0
        public static async Task SetCodePageAsync(this IRExpressionEvaluator evaluation, int codePage, CancellationToken cancellationToken = default(CancellationToken))
        {
            var cp = $".{codePage}";

            if (codePage == 0)
            {
                cp = await evaluation.IsRSessionPlatformWindowsAsync() ? ".437" : "en_US.UTF-8";
            }
            var script = Invariant($"Sys.setlocale('LC_CTYPE', '{cp}')");
            await evaluation.ExecuteAsync(script, cancellationToken);
        }
Ejemplo n.º 13
0
        private static Task LoadRtvsPackage(IRExpressionEvaluator eval, string libPath)
        {
            return(eval.ExecuteAsync(Invariant($@"
if (!base::isNamespaceLoaded('rtvs')) {{
    base::loadNamespace('rtvs', lib.loc = {libPath.ToRStringLiteral()})
}}
if (rtvs:::version != {rtvsPackageVersion}) {{
    warning('This R session was created using an incompatible version of RTVS, and may misbehave or crash when used with this version. Click ""Reset"" to replace it with a new clean session.');
}}
")));
        }
Ejemplo n.º 14
0
        public static Task SetCodePageAsync(this IRExpressionEvaluator evaluation, int codePage, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (codePage == 0)
            {
                // TODO: update this to get the codepage via platform agnostic service
                codePage = 437;
            }
            var script = Invariant($"Sys.setlocale('LC_CTYPE', '.{codePage}')");

            return(evaluation.ExecuteAsync(script, cancellationToken));
        }
Ejemplo n.º 15
0
        public static Task SetLocalLibsAsync(IRExpressionEvaluator eval, params string[] libPaths)
        {
            foreach (var libPath in libPaths.Where(libPath => !Directory.Exists(libPath)))
            {
                Directory.CreateDirectory(libPath);
            }

            var paths = string.Join(",", libPaths.Select(p => p.ToRPath().ToRStringLiteral()));
            var code  = $".libPaths(c({paths}))";

            return(eval.ExecuteAsync(code));
        }
Ejemplo n.º 16
0
        public static async Task SetCodePageAsync(this IRExpressionEvaluator evaluation, int codePage, CancellationToken cancellationToken = default(CancellationToken))
        {
            string cp = $".{codePage}";

            if (codePage == 0)
            {
                var platformType = await evaluation.GetRSessionPlatformAsync(cancellationToken);

                cp = platformType.EqualsIgnoreCase("windows")? ".437": "en_US.UTF-8";
            }
            var script = Invariant($"Sys.setlocale('LC_CTYPE', '{cp}')");
            await evaluation.ExecuteAsync(script, cancellationToken);
        }
Ejemplo n.º 17
0
        private async Task LoadRtvsPackage(IRExpressionEvaluator eval, bool isRemote)
        {
            // Load RTVS R package before doing anything in R since the calls
            // below calls may depend on functions exposed from the RTVS package
            var libPath = isRemote ? await GetRemoteRtvsPackagePath(eval) : Path.GetDirectoryName(typeof(RHost).GetTypeInfo().Assembly.GetAssemblyPath());

            await eval.ExecuteAsync(Invariant($@"
if (!base::isNamespaceLoaded('rtvs')) {{
    base::loadNamespace('rtvs', lib.loc = {libPath.ToRStringLiteral()})
}}
if (rtvs:::version != {rtvsPackageVersion}) {{
    warning('This R session was created using an incompatible version of RTVS, and may misbehave or crash when used with this version. Click ""Reset"" to replace it with a new clean session.');
}}
"));
        }
Ejemplo n.º 18
0
        public static async Task SetCodePageAsync(this IRExpressionEvaluator evaluation, int codePage, CancellationToken cancellationToken = default)
        {
            string cp = null;

            if (codePage == 0)
            {
                // Non-Windows defaults to UTF-8, on Windows leave default alone.
                if (!await evaluation.IsRSessionPlatformWindowsAsync(cancellationToken))
                {
                    cp = "en_US.UTF-8";
                }
            }
            else
            {
                cp = Invariant($".{codePage}");
            }

            if (!string.IsNullOrEmpty(cp))
            {
                var script = Invariant($"Sys.setlocale('LC_CTYPE', '{cp}')");
                await evaluation.ExecuteAsync(script, cancellationToken);
            }
        }
Ejemplo n.º 19
0
 public static Task OptionsSetWidthAsync(this IRExpressionEvaluator evaluation, int width)
 {
     return(evaluation.ExecuteAsync(Invariant($"options(width=as.integer({width}))\n")));
 }
Ejemplo n.º 20
0
        public static Task RemoveCurrentPlotAsync(this IRExpressionEvaluator evaluation)
        {
            var script = "rtvs:::graphics.ide.removeplot()\n";

            return(evaluation.ExecuteAsync(script));
        }
Ejemplo n.º 21
0
        public static Task ClearPlotHistoryAsync(this IRExpressionEvaluator evaluation)
        {
            var script = "rtvs:::graphics.ide.clearplots()\n";

            return(evaluation.ExecuteAsync(script));
        }
Ejemplo n.º 22
0
        public static Task PreviousPlotAsync(this IRExpressionEvaluator evaluation)
        {
            var script = "rtvs:::graphics.ide.previousplot()\n";

            return(evaluation.ExecuteAsync(script));
        }
Ejemplo n.º 23
0
        public static Task ResizePlotAsync(this IRExpressionEvaluator evaluation, int width, int height, int resolution)
        {
            var script = Invariant($"rtvs:::graphics.ide.resize({width}, {height}, {resolution})\n");

            return(evaluation.ExecuteAsync(script));
        }
Ejemplo n.º 24
0
 /// <summary>
 /// Like <see cref="ExecuteAsync(IRExpressionEvaluator, FormattableString, REvaluationKind, CancellationToken)"/>, but uses
 /// <see cref="REvaluationKind.Mutating"/> for <c>kind</c>
 /// </summary>
 public static Task ExecuteAsync(this IRExpressionEvaluator evaluator, FormattableString expression, CancellationToken cancellationToken = default(CancellationToken)) =>
 evaluator.ExecuteAsync(expression, REvaluationKind.Mutating, cancellationToken);
Ejemplo n.º 25
0
 public static Task SetDefaultWorkingDirectoryAsync(this IRExpressionEvaluator evaluation)
 {
     return(evaluation.ExecuteAsync($"setwd('~')\n"));
 }
Ejemplo n.º 26
0
 public static Task SetWorkingDirectoryAsync(this IRExpressionEvaluator evaluation, string path)
 {
     return(evaluation.ExecuteAsync($"setwd('{path.Replace('\\', '/')}')\n"));
 }
Ejemplo n.º 27
0
        public static Task SetFunctionRedirectionAsync(this IRExpressionEvaluator evaluation)
        {
            var script = "rtvs:::redirect_functions()";

            return(evaluation.ExecuteAsync(script));
        }
Ejemplo n.º 28
0
 public static Task SetLocalRepoAsync(IRExpressionEvaluator eval, string localRepoPath) {
     var code = $"options(repos=list(LOCAL=\"file:///{localRepoPath.ToRPath()}\"))";
     return eval.ExecuteAsync(code);
 }
Ejemplo n.º 29
0
 public static Task SetCranRepoAsync(IRExpressionEvaluator eval) {
     var code = @"options(repos=list(CRAN='http://cran.r-project.org'))";
     return eval.ExecuteAsync(code);
 }
Ejemplo n.º 30
0
 private static Task SuppressUI(IRExpressionEvaluator eval)
 {
     // # Suppress Windows UI
     // http://astrostatistics.psu.edu/datasets/R/html/utils/html/winMenus.html
     return(eval.ExecuteAsync(@"rtvs:::suppress_ui()"));
 }
Ejemplo n.º 31
0
 public static Task LoadWorkspaceAsync(this IRExpressionEvaluator evaluation, string path)
 {
     return(evaluation.ExecuteAsync($"load('{path.Replace('\\', '/')}', .GlobalEnv)\n"));
 }
Ejemplo n.º 32
0
 public static async Task SetVsCranSelectionAsync(this IRExpressionEvaluator evaluation, string mirrorUrl)
 {
     await evaluation.ExecuteAsync(Invariant($"rtvs:::set_mirror({mirrorUrl.ToRStringLiteral()})"));
 }
Ejemplo n.º 33
0
 public static Task SaveWorkspaceAsync(this IRExpressionEvaluator evaluation, string path)
 {
     return(evaluation.ExecuteAsync($"save.image(file='{path.Replace('\\', '/')}')\n", REvaluationKind.Normal));
 }