Suppress Stan parser warnings when using rstantools 1.5 build chain


When building an R package based on Stan using the rstantools 1.5 build-chain, I am having trouble suppressing Stan parser warnings. Usually I wouldn’t care if these warnings are shown (they are false positives in my case), but they ultimately cause R CMD check to fail.

My current work-around is to wrap some of the code in stanmodels.R in a call to capture.output as SuppressWarnings seems to have no effect. Is there any better solution for this?


No, except maybe to fix the false positive warnings upstream. What are they? I guess we could put the capture.output thing into the stanmodels.R file in rstanarm so that everyone who downloads that via rstan_package.skeleton does not have to deal with the hurdles you ran into.


The warnings are:

left-hand side variable (name=psi) occurs on right-hand side of assignment, causing inefficient deep copy to avoid aliasing.

and are caused by statements such as

psi[J_item_equal] = psi[J_item_orig];

The problem with capture.output is that it may suppress more than we actually want to suppress so being able to capute Stan warnings via suppressWarnings would be my prefered solutation, if that can be made possible.


It is not actually an R warning, but a C++ exception that happens to have the word “warning” in it. I don’t think the C++ should be copying in this situation though.


I know they are not actual R warnings, but I had hoped one could have passed them via the R warning stream.


In any case, this is how I currently try to handle these warnings:

stanmodels <- lapply(stan_files, function(f) {

type = “message”

Unfortunately, I was wrong it the sense that R CMD check still finds these warnings somewhere… Let’s see if I can suppress them completely.