Example #1
0
        /// <summary>
        /// Asynchronously fetches RD data on the function from R.
        /// </summary>
        public async Task <string> GetFunctionRdDataAsync(string functionName, string packageName)
        {
            if (packageName.EqualsOrdinal("rtvs"))
            {
                return(GetRtvsFunctionRdData(functionName));
            }

            await TaskUtilities.SwitchToBackgroundThread();

            await _host.CreateSessionAsync();

            string command = GetCommandText(functionName, packageName);

            try {
                return(await _host.Session.EvaluateAsync <string>(command, REvaluationKind.Normal));
            } catch (RException) { }

            // Sometimes there is no information in a specific package.
            // For example, Matrix exports 'as.matrix' and base does it as well.
            // However, help('as.matrix', 'Matrix') will fail while help('as.matrix' will succeed.
            command = GetCommandText(functionName, null);
            try {
                return(await _host.Session.EvaluateAsync <string>(command, REvaluationKind.Normal));
            } catch (RException) { }

            return(string.Empty);
        }
Example #2
0
        public async Task BuildIndexAsync()
        {
            var ready = await _buildIndexLock.WaitAsync();

            try {
                if (!ready)
                {
                    var startTotalTime = DateTime.Now;

                    await TaskUtilities.SwitchToBackgroundThread();

                    await _host.CreateSessionAsync();

                    Debug.WriteLine("R function host start: {0} ms", (DateTime.Now - startTotalTime).TotalMilliseconds);

                    var startTime = DateTime.Now;
                    // Fetch list of available packages from R session
                    await BuildPackageListAsync();

                    Debug.WriteLine("R package names/description: {0} ms", (DateTime.Now - startTime).TotalMilliseconds);

                    // Populate function index for preloaded packages first
                    startTime = DateTime.Now;
                    await BuildPreloadedPackagesFunctionListAsync();

                    Debug.WriteLine("R function index (preloaded): {0} ms", (DateTime.Now - startTime).TotalMilliseconds);

                    // Populate function index for all remaining packages
                    startTime = DateTime.Now;
                    await BuildRemainingPackagesFunctionListAsync();

                    Debug.WriteLine("R function index (remaining): {0} ms", (DateTime.Now - startTime).TotalMilliseconds);

                    await _functionIndex.BuildIndexAsync(this);

                    Debug.WriteLine("R function index total: {0} ms", (DateTime.Now - startTotalTime).TotalMilliseconds);
                }
            } catch (RHostDisconnectedException ex) {
                Debug.WriteLine(ex.Message);
            } finally {
                _buildIndexLock.Release();
            }
        }