MCPcopy Index your code
hub / github.com/REditorSupport/vscode-R / executeRCommand

Function executeRCommand

src/util.ts:364–407  ·  view source on GitHub ↗
(rCommand: string, cwd?: string | URL, fallback?: string | ((e: Error) => string))

Source from the content-addressed store, hash-verified

362// Single quotes are ok.
363//
364export async function executeRCommand(rCommand: string, cwd?: string | URL, fallback?: string | ((e: Error) => string)): Promise<string | undefined> {
365 const rPath = await getRpath();
366 if (!rPath) {
367 return undefined;
368 }
369
370 const options: cp.CommonOptions = {
371 cwd: cwd,
372 };
373
374 const lim = '---vsc---';
375 const args = [
376 '--silent',
377 '--no-echo',
378 '--no-save',
379 '--no-restore',
380 '-e', `cat('${lim}')`,
381 '-e', rCommand,
382 '-e', `cat('${lim}')`
383 ];
384
385 let ret: string | undefined = undefined;
386
387 try {
388 const result = await spawnAsync(rPath, args, options);
389 if (result.status !== 0) {
390 throw result.error || new Error(result.stderr);
391 }
392 const re = new RegExp(`${lim}(.*)${lim}`, 'ms');
393 const match = re.exec(result.stdout);
394 if (!match || match.length !== 2) {
395 throw new Error('Could not parse R output.');
396 }
397 ret = match[1];
398 } catch (e) {
399 if (fallback) {
400 ret = (typeof fallback === 'function' ? fallback(catchAsError(e)) : fallback);
401 } else {
402 console.warn(e);
403 }
404 }
405
406 return ret;
407}
408
409
410// This class is a wrapper around Map<string, any> that implements vscode.Memento

Callers 7

createLintrConfigFunction · 0.90
collectRLinkingToFunction · 0.90
makeDraftFunction · 0.90
getCranUrlFunction · 0.85
getRVersionFunction · 0.85
getRPackageVersionFunction · 0.85

Calls 3

getRpathFunction · 0.85
spawnAsyncFunction · 0.85
catchAsErrorFunction · 0.85

Tested by

no test coverage detected