77
88import { error , info , warning } from "log/mod.ts" ;
99import { existsSync } from "fs/exists.ts" ;
10+ import { basename , extname } from "path/mod.ts" ;
1011
1112import * as colors from "fmt/colors.ts" ;
1213
@@ -81,6 +82,9 @@ export const knitrEngine: ExecutionEngine = {
8182 } ,
8283
8384 execute : async ( options : ExecuteOptions ) : Promise < ExecuteResult > => {
85+ const inputBasename = basename ( options . target . input ) ;
86+ const inputStem = basename ( inputBasename , extname ( inputBasename ) ) ;
87+
8488 const result = await callR < ExecuteResult > (
8589 "execute" ,
8690 {
@@ -92,6 +96,10 @@ export const knitrEngine: ExecutionEngine = {
9296 options . tempDir ,
9397 options . projectDir ,
9498 options . quiet ,
99+ // fixup .rmarkdown file references
100+ ( output ) => {
101+ return output . replaceAll ( `${ inputStem } .rmarkdown` , inputBasename ) ;
102+ } ,
95103 ) ;
96104 const includes = result . includes as unknown ;
97105 // knitr appears to return [] instead of {} as the value for includes.
@@ -128,6 +136,7 @@ export const knitrEngine: ExecutionEngine = {
128136 options . tempDir ,
129137 options . projectDir ,
130138 options . quiet ,
139+ undefined ,
131140 false ,
132141 ) . then ( ( ) => {
133142 return Promise . resolve ( ) ;
@@ -163,6 +172,7 @@ async function callR<T>(
163172 tempDir : string ,
164173 projectDir ?: string ,
165174 quiet ?: boolean ,
175+ outputFilter ?: ( output : string ) => string ,
166176 reportError = true ,
167177) : Promise < T > {
168178 // establish cwd for execute (the current dir if there is an renv
@@ -192,7 +202,12 @@ async function callR<T>(
192202 } ,
193203 input ,
194204 "stdout>stderr" ,
195- colors . red ,
205+ ( output ) => {
206+ if ( outputFilter ) {
207+ output = outputFilter ( output ) ;
208+ }
209+ return colors . red ( output ) ;
210+ } ,
196211 ) ;
197212
198213 if ( result . success ) {
0 commit comments