Skip to content

Commit 0487ce5

Browse files
committed
Embedded R code chunks in sourceCpp are now executed within the working directory of the C++ source file.
1 parent 148b054 commit 0487ce5

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

ChangeLog

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
2014-01-31 JJ Allaire <[email protected]>
2+
3+
* R/Attributes.R: Embedded R code chunks in sourceCpp are
4+
now executed within the working directory of the C++ source
5+
file.
6+
17
2014-01-31 Dirk Eddelbuettel <[email protected]>
28

39
* man/Rcpp.package.skeleton.Rd: Also updated

R/Attributes.R

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,16 @@ sourceCpp <- function(file = "",
2424
showOutput = verbose,
2525
verbose = getOption("verbose")) {
2626

27-
# resolve code into a file if necessary
27+
# resolve code into a file if necessary. also track the working
28+
# directory to source the R embedded code chunk within
2829
if (!missing(code)) {
30+
rWorkingDir <- getwd()
2931
file <- tempfile(fileext = ".cpp")
3032
con <- file(file, open = "w")
3133
writeLines(code, con)
3234
close(con)
35+
} else {
36+
rWorkingDir <- dirname(file)
3337
}
3438

3539
# resolve the file path
@@ -167,6 +171,7 @@ sourceCpp <- function(file = "",
167171
# source the embeddedR
168172
if (length(context$embeddedR) > 0) {
169173
srcConn <- textConnection(context$embeddedR)
174+
setwd(rWorkingDir) # will be reset by previous on.exit handler
170175
source(file=srcConn, echo=TRUE)
171176
}
172177

inst/NEWS.Rd

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@
2929
\item New \code{checkUserInterrupt()} function that provides a C++ friendly
3030
implementation of \code{R_CheckUserInterrupt}.
3131
}
32+
\item Changes in Rcpp attributes:
33+
\itemize{
34+
\item Embedded R code chunks in sourceCpp are now executed within
35+
the working directory of the C++ source file.
36+
}
3237
\item Changes in Rcpp documentation:
3338
\itemize{
3439
\item The Rcpp-FAQ and Rcpp-package vignettes have been updated and expanded.

0 commit comments

Comments
 (0)