Incorrect work of track package in R.NET

2019-02-25 16:32发布

问题:

I have same problem when trying to use R.NET with track package (it needs for tracking variables, which were modified via R code ran).

So, it native R code, which works fine:

library(track);
track.start(clobber = "vars", dir = file.path(tempdir(), 'rdata123'));

a <- 5;
print(track.summary());
print(ls(globalenv()));

track.stop();

I have output like this:

> library(track);
> track.start(clobber = "vars", dir = file.path(tempdir(), 'rdata123'));
Tracking <env R_GlobalEnv> (writable) using existing directory     'C:\Users\Rebelion\AppData\Local\Temp\RtmpGmyc4B/rdata123'
> 
> a <- 5;
> print(track.summary());
class    mode extent length size            modified TA TW
a numeric numeric    [1]      1   48 2015-11-19 10:44:34  0  2
> print(ls(globalenv()));
[1] "a"
> 
> track.stop();
Stopping tracking on <env R_GlobalEnv>

So, while I try to realize complementary code via R.NET (see code below)

using System;
using RDotNet;

namespace ConsoleApplication10
{
    class Program
    {
        static void Main(string[] args)
        {
            REngine.SetEnvironmentVariables();
            var engine = REngine.GetInstance();

            engine.Initialize();

            engine.Evaluate("library(track);");
            engine.Evaluate(@"track.start(auto = TRUE, clobber = ""vars"", dir = file.path(tempdir(), 'rdatadir123456'))");

            engine.Evaluate("a <- 5;");
            engine.Evaluate("print(track.summary());");
            engine.Evaluate("print(ls(globalenv()));");

            engine.Evaluate("track.stop();");

            Console.ReadLine();
        }
    }
}

I have another output, where track.summary() doesn't consist of anything:

Tracking <env R_GlobalEnv> (writable) using new directory 'C:\Users\Rebelion\AppData\Local\Temp\RtmpiQEGgY/rdatadir123456'
[1] class    mode     extent   length   size     modified TA       TW
<0 строк> (или 'row.names' нулевой длины)
[1] "a"
Stopping tracking on <env R_GlobalEnv>

What's the reason, does anybody know? Thank you.

标签: r r.net