Skip to content

Commit 3cea01d

Browse files
committed
Merge branch 'master' of github.com:RcppCore/Rcpp
2 parents da7f101 + 335d15e commit 3cea01d

File tree

8 files changed

+154
-108
lines changed

8 files changed

+154
-108
lines changed

ChangeLog

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,19 @@
66
* vignettes/Rcpp-extending.Rnw: Idem
77
* vignettes/Rcpp-sugar.Rnw: Idem
88

9+
2014-01-31 JJ Allaire <[email protected]>
10+
11+
* R/Attributes.R: Embedded R code chunks in sourceCpp are now
12+
executed within the working directory of the C++ source file.
13+
14+
2014-01-31 Dirk Eddelbuettel <[email protected]>
15+
16+
* man/Rcpp.package.skeleton.Rd: Also updated
17+
18+
2014-01-30 Dirk Eddelbuettel <[email protected]>
19+
20+
* vignettes/Rcpp-package.Rnw: Updates for upcoming release
21+
922
2014-01-28 Dirk Eddelbuettel <[email protected]>
1023

1124
* vignettes/Rcpp-FAQ.Rnw: Some updates for upcoming release

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: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,14 @@
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{
34-
\item The Rcpp-FAQ vignette have been updated and expanded.
39+
\item The Rcpp-FAQ and Rcpp-package vignettes have been updated and expanded.
3540
\item Vignettes are now typeset with grey background for code boxes.
3641
}
3742
}

inst/skeleton/rcpp_hello_world.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
rcpp_hello_world <- function(){
3-
.Call( "rcpp_hello_world", PACKAGE = "@PKG@" )
2+
rcpp_hello_world <- function() {
3+
.Call("rcpp_hello_world", PACKAGE = "@PKG@")
44
}
55

inst/skeleton/rcpp_module.cpp

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,29 +25,29 @@ std::string hello() {
2525
throw std::range_error( "boom" ) ;
2626
}
2727

28-
int bar( int x){
29-
return x*2 ;
28+
int bar(int x) {
29+
return x*2;
3030
}
3131

32-
double foo( int x, double y){
33-
return x * y ;
32+
double foo(int x, double y) {
33+
return x * y;
3434
}
3535

36-
void bla( ){
37-
Rprintf( "hello\\n" ) ;
36+
void bla() {
37+
Rprintf("hello\\n");
3838
}
3939

40-
void bla1( int x){
41-
Rprintf( "hello (x = %d)\\n", x ) ;
40+
void bla1(int x) {
41+
Rprintf("hello (x = %d)\\n", x);
4242
}
4343

44-
void bla2( int x, double y){
45-
Rprintf( "hello (x = %d, y = %5.2f)\\n", x, y ) ;
44+
void bla2( int x, double y) {
45+
Rprintf("hello (x = %d, y = %5.2f)\\n", x, y);
4646
}
4747

4848
class World {
4949
public:
50-
World() : msg("hello"){}
50+
World() : msg("hello") {}
5151
void set(std::string msg) { this->msg = msg; }
5252
std::string greet() { return msg; }
5353

@@ -60,25 +60,25 @@ class World {
6060
RCPP_MODULE(yada){
6161
using namespace Rcpp ;
6262

63-
function( "hello" , &hello , "documentation for hello " );
64-
function( "bla" , &bla , "documentation for bla " );
65-
function( "bla1" , &bla1 , "documentation for bla1 " );
66-
function( "bla2" , &bla2 , "documentation for bla2 " );
63+
function("hello" , &hello , "documentation for hello ");
64+
function("bla" , &bla , "documentation for bla ");
65+
function("bla1" , &bla1 , "documentation for bla1 ");
66+
function("bla2" , &bla2 , "documentation for bla2 ");
6767

6868
// with formal arguments specification
69-
function( "bar" , &bar ,
70-
List::create( _["x"] = 0.0 ),
71-
"documentation for bar " ) ;
72-
function( "foo" , &foo ,
73-
List::create( _["x"] = 1, _["y"] = 1.0 ),
74-
"documentation for foo " ) ;
69+
function("bar" , &bar ,
70+
List::create( _["x"] = 0.0),
71+
"documentation for bar ");
72+
function("foo" , &foo ,
73+
List::create( _["x"] = 1, _["y"] = 1.0),
74+
"documentation for foo ");
7575

76-
class_<World>( "World" )
76+
class_<World>("World")
7777
// expose the default constructor
7878
.constructor()
7979

80-
.method( "greet", &World::greet , "get the message" )
81-
.method( "set", &World::set , "set the message" )
80+
.method("greet", &World::greet , "get the message")
81+
.method("set", &World::set , "set the message")
8282
;
8383
}
8484

man/Rcpp.package.skeleton.Rd

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,12 @@ Rcpp.package.skeleton(name = "anRpackage", list = character(),
4040
\details{
4141
In addition to \link[utils]{package.skeleton} :
4242

43-
The \samp{DESCRIPTION} file gains a Depends line requesting that
43+
The \samp{DESCRIPTION} file gains an Imports line requesting that
4444
the package depends on Rcpp and a LinkingTo line so that the package
4545
finds Rcpp header files.
4646

47-
The \samp{NAMESPACE}, if any, gains a \code{useDynLib} directive.
47+
The \samp{NAMESPACE} gains a \code{useDynLib} directive as well
48+
as an \code{importFrom(Rcpp, evalCpp} to ensure instantiation of Rcpp.
4849

4950
The \samp{src} directory is created if it does not exists and
5051
a \samp{Makevars} file is added setting the environment variables

vignettes/Rcpp-FAQ.Rnw

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ against.
318318

319319
On the Linux command-line, you can do the following:\newline
320320
<<lang=bash>>=
321-
$ export PKG_LIBS=`Rscript -e "Rcpp:::LdFlags()"`
321+
$ export PKG_LIBS=`Rscript -e "Rcpp:::LdFlags()"` # if Rcpp older than 0.11.0
322322
$ export PKG_CXXFLAGS=`Rscript -e "Rcpp:::CxxFlags()"`
323323
$ R CMD SHLIB myfile.cpp
324324
@
@@ -332,6 +332,20 @@ Dirk's older 'Intro to HPC with R' tutorial slides). It is still not
332332
recommended as there are tools and automation mechanisms that can do the work
333333
for you.
334334

335+
\pkg{Rcpp} versions 0.11.0 or later can do with the definition of
336+
\code{PKG\_LIBS} as a user-facing library is no longer needed (and hence no
337+
longer shipped with the package). One still needs to set \code{PKG\_CXXFLAGS}
338+
to tell R where the \pkg{Rcpp} headers files are located.
339+
340+
Once \code{R CMD SHLIB} has created the dyanmically-loadable file (with
341+
extension \code{.so} on Linux, \code{.dylib} on OS X or \code{.dll} on
342+
Windows), it can be loaded in an R session via \rdoc{base}{dyn.load}, and the
343+
function can be executed via \rdoc{base}{.Call}. Needless to say, we
344+
\emph{strongly} recommend using a package, or at least Rcpp Attributes as
345+
either approach takes care of a lot of these tedious and error-prone manual
346+
steps.
347+
348+
335349
\subsection{But R CMD SHLIB still does not work !}
336350

337351
We have had reports in the past where build failures occurred when users had
@@ -387,13 +401,14 @@ complain to its vendor if you are still upset.
387401
OS X used to be a little more conservative with compiler versions as Apple
388402
stuck with gcc-4.2. Following the 'Mavericks' release, it is the opposite as
389403
only llvm is provide in Xcode---while the R build provided by CRAN still has
390-
hardwired settings for the gcc/g++ combination. Until that is resolved, users
391-
either need to create softlinks (say, in, \code{/usr/local/bin}) or override
392-
the \code{CC} and \code{CXX} variables via a file \code{~/.R/Makevars} or its
393-
system-equivalent in R's \code{etc/} directory.
404+
hardwired settings for the gcc/g++ combination.
405+
406+
Until that is resolved, users either need to create softlinks (say, in,
407+
\code{/usr/local/bin}) or override the \code{CC} and \code{CXX} variables via
408+
a file \code{~/.R/Makevars} or its system-equivalent in R's \code{etc/}
409+
directory. See the \code{r-sig-mac} mailing for further details.
394410

395-
Compilation from source is recommended. See the \code{r-sig-mac} mailing for
396-
further details.
411+
Compilation from source is recommended.
397412
%At the time of writing this paragraph (in the spring of 2011), \pkg{Rcpp}
398413
%(just like CRAN) supports all OS X releases greater or equal to 10.5.
399414
%However, building \pkg{Rcpp} from source (or building packages using

0 commit comments

Comments
 (0)