Skip to content

Commit d370c5b

Browse files
authored
Merge pull request #1146 from RcppCore/feature/message
Add Rcpp::message
2 parents 5530578 + 004c126 commit d370c5b

File tree

6 files changed

+61
-3
lines changed

6 files changed

+61
-3
lines changed

ChangeLog

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
2021-03-21 Dirk Eddelbuettel <[email protected]>
2+
3+
* inst/include/Rcpp/api/meat/message.h: Add wrapper for base::message
4+
* inst/include/Rcpp/api/meat/meat.h: Include new file
5+
* inst/tinytest/test_misc.R: Simple test
6+
* inst/tinytest/cpp/misc.cpp (messageWrapper): Test support
7+
18
2021-02-23 Dirk Eddelbuettel <[email protected]>
29

310
* Contributing.md: Update unit test link to tinytest

inst/NEWS.Rd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
\ghpr{1138} fixing \ghit{1137})
1515
\item Global \code{Rcout} and \code{Rcerr} objects are supported
1616
via a compiler directive (Iñaki in \ghpr{1139} fixing \ghit{928})
17+
\item Add support for \code{Rcpp::message} (Dirk in \ghpr{1146}
18+
fixing \ghit{1145})
1719
}
1820
\item Changes in Rcpp Attributes:
1921
\itemize{

inst/include/Rcpp/api/meat/meat.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
#include <Rcpp/api/meat/protection.h>
4343
#include <Rcpp/api/meat/wrap.h>
4444

45+
#include <Rcpp/api/meat/message.h>
46+
4547
#ifndef RCPP_NO_MODULES
4648
#include <Rcpp/api/meat/module/Module.h>
4749
#endif

inst/include/Rcpp/api/meat/message.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
2+
// message.h: Rcpp R/C++ interface class library -- Wrapper for base::message
3+
//
4+
// Copyright (C) 2021 Dirk Eddelbuettel
5+
//
6+
// This file is part of Rcpp.
7+
//
8+
// Rcpp is free software: you can redistribute it and/or modify it
9+
// under the terms of the GNU General Public License as published by
10+
// the Free Software Foundation, either version 2 of the License, or
11+
// (at your option) any later version.
12+
//
13+
// Rcpp is distributed in the hope that it will be useful, but
14+
// WITHOUT ANY WARRANTY; without even the implied warranty of
15+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
// GNU General Public License for more details.
17+
//
18+
// You should have received a copy of the GNU General Public License
19+
// along with Rcpp. If not, see <http://www.gnu.org/licenses/>.
20+
21+
#ifndef Rcpp_api_meat_message_h
22+
#define Rcpp_api_meat_message_h
23+
24+
namespace Rcpp {
25+
26+
inline void message(SEXP s) {
27+
Rcpp::Function msg = Rcpp::Environment::base_env()["message"];
28+
msg(s);
29+
}
30+
31+
}
32+
33+
#endif

inst/tinytest/cpp/misc.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,3 +224,8 @@ String testNullableString(Rcpp::Nullable<Rcpp::String> param = R_NilValue) {
224224
else
225225
return String("");
226226
}
227+
228+
// [[Rcpp::export]]
229+
void messageWrapper(SEXP s) {
230+
message(s);
231+
}

inst/tinytest/test_misc.R

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

2-
## Copyright (C) 2010 - 2019 Dirk Eddelbuettel and Romain Francois
2+
## Copyright (C) 2010 - 2021 Dirk Eddelbuettel and Romain Francois
33
##
44
## This file is part of Rcpp.
55
##
@@ -176,9 +176,18 @@ expect_equal(testNullableString("blah"), "blah")
176176
expect_true(nchar(Rcpp:::bib()) > 0, info="bib file")
177177

178178
# test.getRcppVersion <- function() {
179-
expect_true(inherits(getRcppVersion(), "package_version"), info="package_version object")
180-
expect_true(getRcppVersion(devel=TRUE) >= getRcppVersion(devel=FALSE), info="dev greater equal release")
179+
expect_true(inherits(Rcpp::getRcppVersion(), "package_version"), info="package_version object")
180+
expect_true(Rcpp::getRcppVersion(devel=TRUE) >= Rcpp::getRcppVersion(devel=FALSE), info="dev greater equal release")
181181

182182
## if need be it can be useful to fail to test e.g. the Docker setup
183183
## commented out now as we prefer to pass when not debugging ;-)
184184
# expect_true(FALSE, info="oh noes")
185+
186+
## test that a message is output as is, and a suppressedMessage is not
187+
txt <- "ABCdef"
188+
expect_equal(capture.output(messageWrapper(txt), type="message"), txt)
189+
expect_equal(capture.output(suppressMessages(messageWrapper(txt)), type="message"), character())
190+
expect_message(messageWrapper(txt))
191+
## test for message component
192+
msg <- tryCatch(message(txt), message = identity)
193+
expect_equal(msg$message, paste(txt, "\n", sep=""))

0 commit comments

Comments
 (0)