File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -6,12 +6,16 @@ sourceCpp <- function(file = "",
66 showOutput = verbose ,
77 verbose = getOption(" verbose" )) {
88
9- # resolve code into a file if necessary
9+ # resolve code into a file if necessary. also track the working
10+ # directory to source the R embedded code chunk within
1011 if (! missing(code )) {
12+ rWorkingDir <- getwd()
1113 file <- tempfile(fileext = " .cpp" )
1214 con <- file(file , open = " w" )
1315 writeLines(code , con )
1416 close(con )
17+ } else {
18+ rWorkingDir <- dirname(file )
1519 }
1620
1721 # resolve the file path
@@ -148,6 +152,7 @@ sourceCpp <- function(file = "",
148152 # source the embeddedR
149153 if (length(context $ embeddedR ) > 0 ) {
150154 srcConn <- textConnection(context $ embeddedR )
155+ setwd(rWorkingDir ) # will be reset by previous on.exit handler
151156 source(file = srcConn , echo = TRUE )
152157 }
153158
You can’t perform that action at this time.
0 commit comments