Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow silent R output #1126

Closed
DavZim opened this issue Dec 10, 2020 · 4 comments
Closed

Allow silent R output #1126

DavZim opened this issue Dec 10, 2020 · 4 comments

Comments

@DavZim
Copy link

DavZim commented Dec 10, 2020

As outlined in a SO question, when sourcing a cpp-file with embedded R code, there is no option to silence the R output.

This can be seen by running:

Rcpp::sourceCode(code='
#include <Rcpp.h>
// [[Rcpp::export]]
Rcpp::NumericVector timesTwo(Rcpp::NumericVector x) {
  return x * 2;
}
/*** R
times_two <- function(x) timesTwo(x)
*/
')
#> times_two <- function(x) timesTwo(x)

I opened this issue so we can discuss if this is needed.

I use embedded R code to define an R wrapper around a cpp function in one file, reducing the number of files needed (e.g., define a cpp function, which returns a data.frame, then call some dplyr or data.table code on the data.frame). I would like to prevent printing the R code when I call sourceCpp(), for example in some kinds of rmarkdown format.

As pointed out by MrFlick, it would require changing the Attributes.R L217 call to source(), which could include an option showROutput or silenceR or similar.

@eddelbuettel
Copy link
Member

eddelbuettel commented Dec 10, 2020

As I said on SO, I am somewhat ambivalent about it:

  • if you don't want R code to run or show, just don't include it
  • you can wrap suppressMessages() (my fave) or captureOutput() around it
  • (R)Markdown and knitr blocks give you very fine control about what to show up to the chunk line number to control it
  • you could create a trivial mySourceCpp() which maybe strips the R code, and another variant that takes the R code in a different file or...

So colour me not-convinced.

We're also in a quasi-freeze as I am switching to a six-month release cycle with a January release coming. Given the incidents around release 1.0.4 and the very disappointing and childish community behavior experienced there I have little inclination to accept changes close to release as we did then. So we could talk about it for July 2021. But is it really worth it?

That said, the change is trivial and close to meaningless and may never reach than a handful of users.

@kevinushey
Copy link
Contributor

I think the simple fix here is:

  1. Add an option echo (or quiet?) to sourceCpp();
  2. Propagate that down to the source() call.

I don't have strong feelings either way but agree with the general inclination to avoid changes immediately prior to release. At least this should be a safe change though.

@eddelbuettel
Copy link
Member

Yes this is, to paraphrase, Douglas Adams "mostly harmless". But we need it in sourceCpp() and cppFunction().

@eddelbuettel
Copy link
Member

This was more or less a two-liner and has been added. Stll not convinced it is all that useful but hey we aim to please :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants