Dave Jarvis' Repositories

git clone https://repo.autonoma.ca/repo/keenwrite.git

Simplify R bootstrapping

AuthorDaveJarvis <email>
Date2022-01-03 23:56:12 GMT-0800
Commitf18b6c63b41b1b57bf8fe679391c68f9a806de39
Parent9b14a4d
Delta5 lines added, 23 lines removed, 18-line decrease
src/main/java/com/keenwrite/processors/r/InlineRProcessor.java
import org.jetbrains.annotations.NotNull;
-import java.nio.file.Path;
import java.util.HashMap;
import java.util.concurrent.atomic.AtomicBoolean;
*/
public void init() {
- final var bootstrap = getBootstrapScript();
+ final var context = getContext();
+ final var bootstrap = context.getRScript();
if( !bootstrap.isBlank() ) {
- final var wd = getWorkingDirectory();
+ final var wd = context.getRWorkingDir();
final var dir = wd.toString().replace( '\\', '/' );
final var definitions = getContext().getDefinitions();
Engine.eval( replace( bootstrap, map ) );
mReady.set( true );
- } catch( final Exception ignored ) {
+ } catch( final Exception ex ) {
+ clue( ex );
// A problem with the bootstrap script is likely caused by variables
// not being loaded. This implies that the R processor is being invoked
// Copy from the previous index to the end of the string.
return sb.append( text.substring( min( prevIndex, length ) ) ).toString();
- }
-
- /**
- * Return the given path if not {@code null}, otherwise return the path to
- * the user's directory.
- *
- * @return A non-null path.
- */
- private Path getWorkingDirectory() {
- return getContext().getRWorkingDir();
- }
-
- /**
- * Loads the R init script from the application's persisted preferences.
- *
- * @return A non-null string, possibly empty.
- */
- private String getBootstrapScript() {
- return getContext().getRScript();
}
}