Skip to content

Commit de8d3a7

Browse files
committed
Merge @jjallaire's attributes fix re: working directory (closes #101)
1 parent 0c45c2d commit de8d3a7

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

R/Attributes.R

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)