Skip to content

Commit d6594ba

Browse files
authored
Merge pull request #1025 from renkun-ken/export-invisible
Add invisible param to export attribute
2 parents b9e1738 + 3acc3ec commit d6594ba

File tree

3 files changed

+115
-70
lines changed

3 files changed

+115
-70
lines changed

ChangeLog

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2019-11-18 Kun Ren <[email protected]>
2+
3+
* src/attributes.cpp: Add invisible param to export attribute (#1024)
4+
* vignettes/rmd/Rcpp-attributes.Rmd: Add an section of Returning invisible object
5+
16
2019-11-13 Dirk Eddelbuettel <[email protected]>
27

38
* .github/ISSUE_TEMPLATE.md: Another small edit
@@ -11,7 +16,7 @@
1116
2019-11-11 Dirk Eddelbuettel <[email protected]>
1217

1318
* inst/unitTests/runit.packageversion.R: New test
14-
* inst/unitTests/cpp/rcppversion.cpp: Cpp portion of test
19+
* inst/unitTests/cpp/rcppversion.cpp: Cpp portion of test
1520

1621
2019-11-10 Dirk Eddelbuettel <[email protected]>
1722

@@ -29,14 +34,14 @@
2934

3035
* R/Attributes.R: Correct how cppFunction() deals with multiple
3136
depends arguments
32-
37+
3338
2019-11-08 Romain Francois <[email protected]>
3439

3540
* inst/include/Rcpp/lang.h: Safer Rcpp_list* and Rcpp_lang*
3641
* inst/include/Rcpp/Function.h: Add Function.invoke() for operator()
3742
* inst/include/Rcpp/generated/Function__operator.h: Safer
3843
Function.operator() using Function.invoke()
39-
44+
4045
2019-11-08 Dirk Eddelbuettel <[email protected]>
4146

4247
* DESCRIPTION (Date, Version): Release 1.0.3
@@ -49,7 +54,7 @@
4954
2019-11-06 Dirk Eddelbuettel <[email protected]>
5055

5156
* DESCRIPTION (Version, Date): Roll minor version
52-
57+
5358
* inst/include/Rcpp/XPtr.h: Provided fallback for old constructor
5459
when C++11 is not available (follow-up to #1003)
5560
* inst/unitTests/runit.XPTr.R (test.XPtr): On Windows (as a proxy for
@@ -69,7 +74,7 @@
6974
* inst/include/Rcpp/proxy/FieldProxy.h: Idem (inside Rf_lang3 and 4)
7075

7176
2019-10-31 Romain Francois <[email protected]>
72-
77+
7378
* inst/include/Rcpp/DataFrame.h: Protect temporaries from gc
7479
* inst/include/Rcpp/Environment.h: Idem
7580
* inst/include/Rcpp/r_cast.h: Idem
@@ -88,7 +93,7 @@
8893
* vignettes/Rcpp-package.Rnw: Another wrapper
8994
* vignettes/Rcpp-jss-2011.Rnw: Idem
9095

91-
* vignettes/Makefile: Refinements
96+
* vignettes/Makefile: Refinements
9297
* vignettes/rmd/Makefile: Idem
9398

9499
* cleanup: Removed bashism, added invocation of make clean
@@ -99,7 +104,7 @@
99104
* vignettes/Makefile: Added
100105

101106
2019-10-21 Dirk Eddelbuettel <[email protected]>
102-
107+
103108
* vignettes/rmd/*: Moved from parent directory
104109
* vignettes/pdf/*: New target directory
105110

@@ -142,7 +147,7 @@
142147
2019-10-01 Dirk Eddelbuettel <[email protected]>
143148

144149
* DESCRIPTION (Version, Date): Roll minor version
145-
150+
146151
2019-09-30 Kevin Ushey <[email protected]>
147152

148153
* inst/include/Rcpp.h: add RCPP_NO_MODULES

src/attributes.cpp

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ namespace attributes {
153153
const char * const kExportAttribute = "export";
154154
const char * const kExportName = "name";
155155
const char * const kExportRng = "rng";
156+
const char * const kExportInvisible = "invisible";
156157
const char * const kInitAttribute = "init";
157158
const char * const kDependsAttribute = "depends";
158159
const char * const kPluginsAttribute = "plugins";
@@ -381,6 +382,15 @@ namespace attributes {
381382
return true;
382383
}
383384

385+
bool invisible() const {
386+
Param invisibleParam = paramNamed(kExportInvisible);
387+
if (!invisibleParam.empty())
388+
return invisibleParam.value() == kParamValueTrue || // #nocov
389+
invisibleParam.value() == kParamValueTRUE; // #nocov
390+
else
391+
return false;
392+
}
393+
384394
const std::vector<std::string>& roxygen() const { return roxygen_; }
385395

386396
private:
@@ -1352,7 +1362,8 @@ namespace attributes {
13521362
// parameter that isn't name or rng
13531363
else if (!value.empty() &&
13541364
(name != kExportName) &&
1355-
(name != kExportRng)) {
1365+
(name != kExportRng) &&
1366+
(name != kExportInvisible)) {
13561367
rcppExportWarning("Unrecognized parameter '" + name + "'",
13571368
lineNumber);
13581369
}
@@ -1366,6 +1377,16 @@ namespace attributes {
13661377
lineNumber); // #nocov end
13671378
}
13681379
}
1380+
// invisible that isn't true of false
1381+
else if (name == kExportInvisible) {
1382+
if (value != kParamValueFalse &&
1383+
value != kParamValueTrue &&
1384+
value != kParamValueFALSE &&
1385+
value != kParamValueTRUE) {
1386+
rcppExportWarning("invisible value must be true or false",
1387+
lineNumber); // #nocov end
1388+
}
1389+
}
13691390
}
13701391
}
13711392

@@ -2413,11 +2434,14 @@ namespace attributes {
24132434
// determine the function name
24142435
std::string name = attribute.exportedName();
24152436

2437+
// determine if return invisible
2438+
bool isInvisibleOrVoid = function.type().isVoid() || attribute.invisible();
2439+
24162440
// write the function
24172441
ostr() << name << " <- function(" << args << ") {"
24182442
<< std::endl;
24192443
ostr() << " ";
2420-
if (function.type().isVoid())
2444+
if (isInvisibleOrVoid)
24212445
ostr() << "invisible("; // #nocov
24222446
ostr() << ".Call(";
24232447
if (!registration_)
@@ -2435,7 +2459,7 @@ namespace attributes {
24352459
for (size_t i = 0; i<arguments.size(); i++)
24362460
ostr() << ", " << arguments[i].name(); // #nocov
24372461
ostr() << ")";
2438-
if (function.type().isVoid())
2462+
if (isInvisibleOrVoid)
24392463
ostr() << ")"; // #nocov
24402464
ostr() << std::endl;
24412465

0 commit comments

Comments
 (0)