Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add startup argument and flowr config file entry for changing the R shell's R executable #718

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,15 @@ export interface FlowrConfigOptions extends MergeableRecord {
* Whether source calls should be ignored, causing {@link processSourceCall}'s behavior to be skipped
*/
ignoreSourceCalls: boolean
/**
* The path to the R executable to use. If this is undefined, {@link DEFAULT_R_PATH} will be used.
*/
rPath: string | undefined
}

export const defaultConfigOptions: FlowrConfigOptions = {
ignoreSourceCalls: false
ignoreSourceCalls: false,
rPath: undefined
}
export const defaultConfigFile = 'flowr.json'

Expand Down
5 changes: 4 additions & 1 deletion src/flowr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ export const optionDefinitions: OptionDefinition[] = [
{ name: 'execute', alias: 'e', type: String, description: 'Execute the given command and exit. Use a semicolon ";" to separate multiple commands.', typeLabel: '{underline command}', multiple: false },
{ name: 'no-ansi', type: Boolean, description: 'Disable ansi-escape-sequences in the output. Useful, if you want to redirect the output to a file.' },
{ name: 'script', alias: 's', type: String, description: `The sub-script to run (${scriptsText})`, multiple: false, defaultOption: true, typeLabel: '{underline files}', defaultValue: undefined },
{ name: 'config-file', type: String, description: 'The name of the configuration file to use', multiple: false }
{ name: 'config-file', type: String, description: 'The name of the configuration file to use', multiple: false },
{ name: 'r-path', type: String, description: 'The path to the R executable to use. Defaults to your PATH.', multiple: false }
]

export interface FlowrCliOptions {
Expand All @@ -51,6 +52,7 @@ export interface FlowrCliOptions {
execute: string | undefined
script: string | undefined
'config-file': string
'r-path': string | undefined
}

export const optionHelp = [
Expand Down Expand Up @@ -95,6 +97,7 @@ function retrieveShell(): RShell {
console.log(formatter.format(`R process exited with code ${code}${signalText}. Restarting...`, { color: Colors.Magenta, effect: ColorEffect.Foreground }))
console.log(italic(`If you want to exit, press either Ctrl+C twice, or enter ${bold(':quit')}`))
},
pathToRExecutable: options['r-path']
})
}

Expand Down
4 changes: 3 additions & 1 deletion src/r-bridge/shell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type { SemVer } from 'semver'
import semver from 'semver/preload'
import { getPlatform } from '../util/os'
import fs from 'fs'
import { getConfig } from '../config'

export type OutputStreamSelector = 'stdout' | 'stderr' | 'both';

Expand Down Expand Up @@ -89,8 +90,9 @@ export interface RShellOptions extends RShellSessionOptions {
readonly sessionName: string
}

export const DEFAULT_R_PATH = getPlatform() === 'windows' ? 'R.exe' : 'R'
export const DEFAULT_R_SHELL_EXEC_OPTIONS: RShellExecutionOptions = {
pathToRExecutable: getPlatform() === 'windows' ? 'R.exe' : 'R',
pathToRExecutable: getConfig().rPath ?? DEFAULT_R_PATH,
commandLineOptions: ['--vanilla', '--quiet', '--no-echo', '--no-save'],
cwd: process.cwd(),
env: process.env,
Expand Down
Loading