Skip to content

Commit

Permalink
wip: try with automatic retrieval of R_LIBS_USER by R
Browse files Browse the repository at this point in the history
  • Loading branch information
EagleoutIce committed Sep 16, 2023
1 parent 1004f0f commit 8dce557
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/r-bridge/shell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ export interface RShellSessionOptions extends MergeableRecord {
readonly revive: 'never' | 'on-error' | 'always'
/** Called when the R session is restarted, this makes only sense if `revive` is not set to `'never'` */
readonly onRevive: (code: number, signal: string | null) => void
/** The path to the library directory */
readonly homeLibPath: string
/** The path to the library directory, use undefined to let R figure that out for itself */
readonly homeLibPath: string | undefined
}

/**
Expand All @@ -88,7 +88,7 @@ export const DEFAULT_R_SHELL_OPTIONS: RShellOptions = {
cwd: process.cwd(),
env: process.env,
eol: EOL,
homeLibPath: process.env.R_LIBS_USER ?? getPlatform() === 'windows' ? 'C:/R/library' : '~/.r-libs',
homeLibPath: undefined,
revive: 'never',
onRevive: () => { /* do nothing */ }
} as const
Expand Down Expand Up @@ -221,9 +221,13 @@ export class RShell {

public tryToInjectHomeLibPath(): void {
// ensure the path exists first
log.debug(`ensuring home lib path exists`)
this.sendCommand(`dir.create(path=${ts2r(this.options.homeLibPath)},showWarnings=FALSE,recursive=TRUE)`)
this.injectLibPaths(this.options.homeLibPath)
if(this.options.homeLibPath === undefined) {
log.debug(`ensuring home lib path exists`)
this.sendCommand(`dir.create(path=Sys.getenv("R_LIBS_USER"),showWarnings=FALSE,recursive=TRUE)`)
this.sendCommand(`.libPaths(c(.libPaths(), Sys.getenv("R_LIBS_USER")))`)
} else {
this.injectLibPaths(this.options.homeLibPath)
}
}

/**
Expand Down

0 comments on commit 8dce557

Please sign in to comment.