(quote = false, overwriteConfig?: string)
| 96 | } |
| 97 | |
| 98 | export async function getRpath(quote = false, overwriteConfig?: string): Promise<string | undefined> { |
| 99 | let rpath: string | undefined = ''; |
| 100 | |
| 101 | // try the config entry specified in the function arg: |
| 102 | if (overwriteConfig) { |
| 103 | rpath = config().get<string>(overwriteConfig); |
| 104 | } |
| 105 | |
| 106 | // try the os-specific config entry for the rpath: |
| 107 | const configEntry = getRPathConfigEntry(); |
| 108 | rpath ||= config().get<string>(configEntry); |
| 109 | rpath &&= substituteVariables(rpath); |
| 110 | |
| 111 | // read from path/registry: |
| 112 | rpath ||= await getRpathFromSystem(); |
| 113 | |
| 114 | // represent all invalid paths (undefined, '', null) as undefined: |
| 115 | rpath ||= undefined; |
| 116 | |
| 117 | if (!rpath) { |
| 118 | // inform user about missing R path: |
| 119 | void vscode.window.showErrorMessage(`Cannot find R to use for help, package installation etc. Change setting r.${configEntry} to R path.`); |
| 120 | } else if (quote && /^[^'"].* .*[^'"]$/.exec(rpath)) { |
| 121 | // if requested and rpath contains spaces, add quotes: |
| 122 | rpath = `"${rpath}"`; |
| 123 | } else if (!quote) { |
| 124 | rpath = rpath.replace(/^"(.*)"$/, '$1'); |
| 125 | rpath = rpath.replace(/^'(.*)'$/, '$1'); |
| 126 | } else if (process.platform === 'win32' && /^'.* .*'$/.exec(rpath)) { |
| 127 | // replace single quotes with double quotes on windows |
| 128 | rpath = rpath.replace(/^'(.*)'$/, '"$1"'); |
| 129 | } |
| 130 | |
| 131 | return rpath; |
| 132 | } |
| 133 | |
| 134 | export async function getRterm(): Promise<string | undefined> { |
| 135 | const configEntry = getRPathConfigEntry(true); |
no test coverage detected