()
| 246 | |
| 247 | // call R script `getAliases.R` and parse the output |
| 248 | private async getAliasesFromR(): Promise<undefined | AllPackageAliases> { |
| 249 | const lim = '---vsc---'; |
| 250 | const options: cp.CommonOptions = { |
| 251 | cwd: this.cwd, |
| 252 | env: { |
| 253 | ...process.env, |
| 254 | VSCR_LIB_PATHS: getRLibPaths(), |
| 255 | VSCR_LIM: lim, |
| 256 | VSCR_USE_RENV_LIB_PATH: config().get<boolean>('useRenvLibPath') ? 'TRUE' : 'FALSE' |
| 257 | } |
| 258 | }; |
| 259 | |
| 260 | const args = [ |
| 261 | '--silent', |
| 262 | '--no-echo', |
| 263 | '--no-save', |
| 264 | '--no-restore', |
| 265 | '-f', |
| 266 | this.rScriptFile |
| 267 | ]; |
| 268 | |
| 269 | try { |
| 270 | const result = await spawnAsync(this.rPath, args, options); |
| 271 | if (result.status !== 0) { |
| 272 | throw result.error || new Error(result.stderr); |
| 273 | } |
| 274 | const re = new RegExp(`${lim}(.*)${lim}`, 'ms'); |
| 275 | const match = re.exec(result.stdout); |
| 276 | if (match?.length !== 2) { |
| 277 | throw new Error('Could not parse R output.'); |
| 278 | } |
| 279 | const json = match[1]; |
| 280 | return <AllPackageAliases>JSON.parse(json) || {}; |
| 281 | } catch (e) { |
| 282 | console.log(e); |
| 283 | void window.showErrorMessage(catchAsError(e).message); |
| 284 | } |
| 285 | } |
| 286 | } |
no test coverage detected