Skip to content

Commit 98173e5

Browse files
authored
Merge pull request #1138 from RcppCore/feature/echo_param_sourcecpp
Add echo parameter to sourcecpp
2 parents 2868f38 + 25d6f7f commit 98173e5

File tree

8 files changed

+70
-48
lines changed

8 files changed

+70
-48
lines changed

ChangeLog

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
2021-01-21 Dirk Eddelbuettel <edd@debian.org>
2+
3+
* DESCRIPTION (Version, Date): Roll minor version
4+
* inst/include/Rcpp/config.h: Idem
5+
6+
* inst/include/Rcpp/DataFrame.h: Remove unused variable
7+
8+
* R/Attributes.R (sourceCpp): Support argument echo to be passed to
9+
source() to silence optional R evaluation
10+
111
2021-01-19 Dirk Eddelbuettel <edd@debian.org>
212

313
* DESCRIPTION (Version, Date): Roll minor version

DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: Rcpp
22
Title: Seamless R and C++ Integration
3-
Version: 1.0.6.3
4-
Date: 2021-01-19
3+
Version: 1.0.6.4
4+
Date: 2021-01-21
55
Author: Dirk Eddelbuettel, Romain Francois, JJ Allaire, Kevin Ushey, Qiang Kou,
66
Nathan Russell, Douglas Bates and John Chambers
77
Maintainer: Dirk Eddelbuettel <edd@debian.org>

R/Attributes.R

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ sourceCpp <- function(file = "",
2828
showOutput = verbose,
2929
verbose = getOption("verbose"),
3030
dryRun = FALSE,
31-
windowsDebugDLL = FALSE) {
31+
windowsDebugDLL = FALSE,
32+
echo = TRUE) {
3233

3334
# use an architecture/version specific subdirectory of the cacheDir
3435
# (since cached dynlibs can now perist across sessions we need to be
@@ -214,7 +215,7 @@ sourceCpp <- function(file = "",
214215
if (embeddedR && (length(context$embeddedR) > 0)) {
215216
srcConn <- textConnection(context$embeddedR)
216217
setwd(rWorkingDir) # will be reset by previous on.exit handler
217-
source(file = srcConn, local = env, echo = TRUE)
218+
source(file = srcConn, local = env, echo = echo)
218219
}
219220

220221
# cleanup the cache dir if requested
@@ -258,7 +259,8 @@ cppFunction <- function(code,
258259
rebuild = FALSE,
259260
cacheDir = getOption("rcpp.cache.dir", tempdir()),
260261
showOutput = verbose,
261-
verbose = getOption("verbose")) {
262+
verbose = getOption("verbose"),
263+
echo = TRUE) {
262264

263265
# process depends
264266
if (!is.null(depends) && length(depends) > 0) { # #nocov start
@@ -315,7 +317,8 @@ cppFunction <- function(code,
315317
rebuild = rebuild,
316318
cacheDir = cacheDir,
317319
showOutput = showOutput,
318-
verbose = verbose)
320+
verbose = verbose,
321+
echo = echo)
319322

320323
# verify that a single function was exported and return it
321324
if (length(exported$functions) == 0)

inst/NEWS.Rd

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,17 @@
88
\item Changes in Rcpp API:
99
\itemize{
1010
\item Refactored \code{Rcpp_PreserveObject} and \code{Rcpp_ReleaseObject}
11-
which are now O(1) (Dirk and Iñaki in \ghpr{1133} and \ghor{1135}
11+
which are now O(1) (Dirk and Iñaki in \ghpr{1133} and \ghpr{1135}
1212
fixing \ghit{382} and \ghit{1081}).
13+
\item A spuriously assigned variable was removed (Dirk in
14+
\ghpr{1138} fixing \ghit{1137})
1315
}
1416
\item Changes in Rcpp Attributes:
1517
\itemize{
1618
\item Packages with dots in their name can now have per-package
1719
include files (Dirk in \ghpr{1132} fixes \ghit{1129}).
20+
\item New argument \code{echo} to quieten optional evaluation in
21+
\code{sourceCpp} (Dirk in \ghpr{1138} fixing \ghit{1126}).
1822
}
1923
}
2024
}

inst/include/Rcpp/DataFrame.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// DataFrame.h: Rcpp R/C++ interface class library -- data frames
44
//
5-
// Copyright (C) 2010 - 2015 Dirk Eddelbuettel and Romain Francois
5+
// Copyright (C) 2010 - 2021 Dirk Eddelbuettel and Romain Francois
66
//
77
// This file is part of Rcpp.
88
//
@@ -106,7 +106,7 @@ namespace Rcpp{
106106
Parent::push_front(object, name);
107107
set_type_after_push();
108108
}
109-
109+
110110
// Offer multiple variants to accomodate both old interface here and signatures in other classes
111111
inline int nrows() const { return DataFrame_Impl::nrow(); }
112112
inline int rows() const { return DataFrame_Impl::nrow(); }
@@ -133,7 +133,6 @@ namespace Rcpp{
133133
void set_type_after_push(){
134134
int max_rows = 0;
135135
bool invalid_column_size = false;
136-
SEXP data = Parent::get__();
137136
List::iterator it;
138137
// Get the maximum number of rows
139138
for (it = Parent::begin(); it != Parent::end(); ++it) {

inst/include/Rcpp/config.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
#define RCPP_VERSION_STRING "1.0.6"
3131

3232
// the current source snapshot
33-
#define RCPP_DEV_VERSION RcppDevVersion(1,0,6,3)
34-
#define RCPP_DEV_VERSION_STRING "1.0.6.3"
33+
#define RCPP_DEV_VERSION RcppDevVersion(1,0,6,4)
34+
#define RCPP_DEV_VERSION_STRING "1.0.6.4"
3535

3636
#endif

man/cppFunction.Rd

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ Dynamically define an R function with C++ source code. Compiles and links a shar
88
}
99
\usage{
1010
cppFunction(code, depends = character(), plugins = character(), includes = character(),
11-
env = parent.frame(), rebuild = FALSE, cacheDir = getOption("rcpp.cache.dir",
12-
tempdir()), showOutput = verbose, verbose = getOption("verbose"))
11+
env = parent.frame(), rebuild = FALSE, cacheDir = getOption("rcpp.cache.dir",
12+
tempdir()), showOutput = verbose, verbose = getOption("verbose"), echo = TRUE)
1313
}
1414

1515
\arguments{
@@ -39,11 +39,14 @@ cppFunction(code, depends = character(), plugins = character(), includes = chara
3939
}
4040
\item{verbose}{
4141
\code{TRUE} to print detailed information about generated code to the console.
42+
}
43+
\item{echo}{
44+
\code{TRUE} to silence output from optional R evaluation if set to \code{FALSE}.
4245
}
4346
}
4447
\details{
4548
Functions defined using \code{cppFunction} must have return types that are compatible with \code{Rcpp::wrap} and parameter types that are compatible with \code{Rcpp::as}.
46-
49+
4750
The shared library will not be rebuilt if the underlying code has not changed since the last compilation.
4851
}
4952
\value{
@@ -63,36 +66,36 @@ cppFunction(code, depends = character(), plugins = character(), includes = chara
6366

6467
cppFunction(
6568
'int fibonacci(const int x) {
66-
if (x == 0) return(0);
69+
if (x == 0) return(0);
6770
if (x == 1) return(1);
6871
return (fibonacci(x - 1)) + fibonacci(x - 2);
6972
}')
7073

7174
cppFunction(depends = "RcppArmadillo",
7275
'List fastLm(NumericVector yr, NumericMatrix Xr) {
73-
76+
7477
int n = Xr.nrow(), k = Xr.ncol();
75-
76-
arma::mat X(Xr.begin(), n, k, false);
78+
79+
arma::mat X(Xr.begin(), n, k, false);
7780
arma::colvec y(yr.begin(), yr.size(), false);
78-
81+
7982
arma::colvec coef = arma::solve(X, y);
8083
arma::colvec resid = y - X*coef;
81-
84+
8285
double sig2 = arma::as_scalar(arma::trans(resid)*resid/(n-k) );
8386
arma::colvec stderrest = arma::sqrt(
8487
sig2 * arma::diagvec(arma::inv(arma::trans(X)*X)));
85-
88+
8689
return List::create(Named("coefficients") = coef,
8790
Named("stderr") = stderrest
8891
);
8992
}')
90-
93+
9194
cppFunction(plugins=c("cpp11"), '
9295
int useCpp11() {
9396
auto x = 10;
9497
return x;
9598
}')
96-
99+
97100
}
98101
}

man/sourceCpp.Rd

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@ Source C++ Code from a File or String
88
and RCPP_MODULE declarations. A shared library is then built and its exported functions and Rcpp modules are made available in the specified environment.
99
}
1010
\usage{
11-
sourceCpp(file = "", code = NULL, env = globalenv(), embeddedR = TRUE, rebuild = FALSE,
11+
sourceCpp(file = "", code = NULL, env = globalenv(), embeddedR = TRUE, rebuild = FALSE,
1212
cacheDir = getOption("rcpp.cache.dir", tempdir()), cleanupCacheDir = FALSE,
1313
showOutput = verbose, verbose = getOption("verbose"), dryRun = FALSE,
14-
windowsDebugDLL = FALSE)
14+
windowsDebugDLL = FALSE, echo = TRUE)
1515
}
1616
\arguments{
1717
\item{file}{
1818
A character string giving the path name of a file
1919
}
2020
\item{code}{
21-
A character string with source code. If supplied, the code is taken from this string instead of a file.
21+
A character string with source code. If supplied, the code is taken from this string instead of a file.
2222
}
2323
\item{env}{
2424
Environment where the R functions and modules should be made available.
@@ -47,30 +47,33 @@ actually executing the commands).
4747
}
4848
\item{windowsDebugDLL}{
4949
\code{TRUE} to create a debug DLL on Windows (and ignored on other platforms).
50+
}
51+
\item{echo}{
52+
\code{TRUE} to silence output from optional R evaluation if set to \code{FALSE}.
5053
}
5154
}
5255
\details{
5356
If the \code{code} parameter is provided then the \code{file} parameter is ignored.
5457

55-
Functions exported using \code{sourceCpp} must meet several conditions,
56-
including being defined in the global namespace and having return types
57-
that are compatible with \code{Rcpp::wrap} and parameter types that are
58-
compatible with \code{Rcpp::as}.
58+
Functions exported using \code{sourceCpp} must meet several conditions,
59+
including being defined in the global namespace and having return types
60+
that are compatible with \code{Rcpp::wrap} and parameter types that are
61+
compatible with \code{Rcpp::as}.
5962
See the \code{\link[=exportAttribute]{Rcpp::export}} documentation for more details.
60-
61-
Content of Rcpp Modules will be automatically loaded into the specified
62-
environment using the \code{\link[=Module]{Module}} and
63-
\code{\link[=populate]{populate}} functions.
64-
65-
If the source file has compilation dependencies on other
66-
packages (e.g. \pkg{Matrix}, \pkg{RcppArmadillo}) then an
67-
\code{\link[=dependsAttribute]{Rcpp::depends}} attribute
68-
should be provided naming these dependencies.
69-
70-
It's possible to embed chunks of R code within a C++ source file by
71-
including the R code within a block comment with the
63+
64+
Content of Rcpp Modules will be automatically loaded into the specified
65+
environment using the \code{\link[=Module]{Module}} and
66+
\code{\link[=populate]{populate}} functions.
67+
68+
If the source file has compilation dependencies on other
69+
packages (e.g. \pkg{Matrix}, \pkg{RcppArmadillo}) then an
70+
\code{\link[=dependsAttribute]{Rcpp::depends}} attribute
71+
should be provided naming these dependencies.
72+
73+
It's possible to embed chunks of R code within a C++ source file by
74+
including the R code within a block comment with the
7275
prefix of \code{/*** R}. For example:
73-
76+
7477
\preformatted{
7578
/*** R
7679
@@ -80,11 +83,11 @@ fibonacci(10)
8083
*/
8184
}
8285
83-
Multiple R code chunks can be included in a C++ file. R code is sourced after the C++ compilation is completed so all functions and modules will be available to the R code.
86+
Multiple R code chunks can be included in a C++ file. R code is sourced after the C++ compilation is completed so all functions and modules will be available to the R code.
8487
}
8588
8689
\value{
87-
Returns (invisibly) a list with two elements:
90+
Returns (invisibly) a list with two elements:
8891
\tabular{ll}{
8992
\code{functions} \tab Names of exported functions\cr
9093
\code{modules} \tab Names of Rcpp modules\cr
@@ -95,9 +98,9 @@ fibonacci(10)
9598
The \code{sourceCpp} function will not rebuild the shared library if the source file has not changed since the last compilation.
9699
97100
The \code{sourceCpp} function is designed for compiling a standalone source file whose only dependencies are R packages. If you are compiling more than one source file or have external dependencies then you should create an R package rather than using \code{sourceCpp}. Note that the \code{\link[=exportAttribute]{Rcpp::export}} attribute can also be used within packages via the \code{\link{compileAttributes}} function.
98-
101+
99102
If you are sourcing a C++ file from within the \code{src} directory of a package then the package's \code{LinkingTo} dependencies, \code{inst/include}, and \code{src} directories are automatically included in the compilation.
100-
103+
101104
If no \code{Rcpp::export} attributes or \code{RCPP_MODULE} declarations are found within the source file then a warning is printed to the console. You can disable this warning by setting the \code{rcpp.warnNoExports} option to \code{FALSE}.
102105

103106
}

0 commit comments

Comments
 (0)