Dave Jarvis' Repositories

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

Inject R output directly into Markdown

AuthorDaveJarvis <email>
Date2021-12-30 15:16:32 GMT-0800
Commit28aae82cdd3fec80d8fe116a5906867f7e35dd04
Parentd8a84b5
Delta5 lines added, 15 lines removed, 10-line decrease
src/main/java/com/keenwrite/processors/r/Engine.java
import javax.script.ScriptEngineManager;
import java.util.Map;
-import java.util.function.Function;
import static com.keenwrite.Messages.get;
*
* @param r R expression to evaluate.
- * @param f Post-processing to apply after evaluating the R expression.
* @return The object resulting from the evaluation.
*/
- public static String eval( final String r, final Function<String, String> f ) {
- return sCache.computeIfAbsent( r, __ -> f.apply( eval( r ) ) );
+ public static String eval( final String r ) {
+ return sCache.computeIfAbsent( r, __ -> evaluate( r ) );
}
/**
* Returns the result of an R expression as an object converted to string.
*
* @param r R expression to evaluate.
* @return The object resulting from the evaluation.
*/
- public static String eval( final String r ) {
+ private static String evaluate( final String r ) {
try {
return ENGINE.eval( r ).toString();
src/main/java/com/keenwrite/processors/r/InlineRProcessor.java
import com.keenwrite.processors.ProcessorContext;
import com.keenwrite.processors.VariableProcessor;
-import com.keenwrite.processors.markdown.extensions.r.ROutputProcessor;
import com.keenwrite.util.InterpolatingMap;
import javafx.beans.property.Property;
public final class InlineRProcessor extends VariableProcessor {
private static final int PREFIX_LENGTH = PREFIX.length();
-
- /**
- * Converts the given string to HTML, trimming new lines, and inlining
- * the text if it is a paragraph. Otherwise, the resulting HTML is most likely
- * complex (e.g., a Markdown table) and should be rendered as its HTML
- * equivalent.
- */
- private final Processor<String> mPostProcessor = new ROutputProcessor();
/**
try {
// Append the string representation of the result into the text.
- sb.append( Engine.eval( r, mPostProcessor ) );
+ sb.append( Engine.eval( r ) );
} catch( final Exception ex ) {
// Inform the user that there was a problem.
src/main/java/com/keenwrite/processors/r/RProcessor.java
final var irp = new InlineRProcessor( IDENTITY, context );
final var rvp = new RVariableProcessor( irp, context );
+
mProcessor = new ExecutorProcessor<>( rvp );
mInlineRProcessor = irp;