I am calling a R function through Rcpp and RInside in my c++ program in
Linux. There are a lot of warning messages saying "no graphics system to
unregister" that were outputed to my log file, which leaded to a hug log
file that I can hardly open after letting the code run for a few hours. Is
there anyone who knows the reason and how to avoid the printing of such
warning messages? I appreciate for your help!
| ?
| I am calling a R function through Rcpp and RInside in my c++ program in Linux.
| There are a lot of warning messages saying "no graphics system to unregister"
| that were outputed to my log file, which leaded to a hug log file that I can
| hardly open after letting the code run for a few hours. Is there anyone who
| knows the reason and how to avoid the printing of such warning messages? I
| appreciate for your help!
Without a minimal reproducible example, nobody is going to be able to help
you.
Dirk
"Outside of a dog, a book is a man's best friend. Inside of a dog, it is too
dark to read." -- Groucho Marx
I am calling a R function through Rcpp and RInside in my c++ program
in Linux. There are a lot of warning messages saying "no graphics
system to unregister" ...Is there anyone who knows the reason and how
to avoid the printing of such warning messages?
Generally, once you track down the line causing the problem,
suppressWarnings() (an R function) might help. Or
suppressPackageStartupMessages() or suppressMessages() may help.
For the cause, are you running on a machine with no GUI or X server?
However, a google suggests this is a message related to shutting down R,
and implies your script has corrupted something. There appears to be no
fix as they, like Dirk, insisted on a reproducible example.
I'm wondering why you would be starting up and shutting down R so many
times in your script. Do you create one RInside instance, either as a
global, or in main() and then pass it around by reference? Or are you
create RInside instances inside other functions, or inside loop bodies?
If the latter, can you refactor to do the former so you only have one
instance?
HTH,
Darren
--
Darren Cook, Software Researcher/Developer
http://dcook.org/work/ (About me and my work)
http://dcook.org/blogs.html (My blogs and articles)
Here is the test code I first used to call the R function from C++ program.
At the end, the warning message came out.
double two_sample_logrank(RInside R, double* t, int* d, int sample_size)
{
double p_val = 0;
int n = 2*sample_size;
std::string txt = // load library, run regression, create
summary
"suppressMessages(require(splines));"
"suppressMessages(require(survival))";
R.parseEvalQ(txt); // eval command, no return
double* g = new double[n];
int i = 0;
for(i=0; i<sample_size; i++) g[i] = 1;
for(i=sample_size; i<n; i++) g[i] = 2;
/* construct vectors used in R from double* and int* */
std::vector<double> std_t(t, &t[n]);
R["t"] = std_t;
std::vector<int> std_d(d, &d[n]);
R["d"] = std_d;
std::vector<int> std_g(g, &g[n]);
R["g"] = std_g;
txt = "df <- data.frame(t,d,g);"
"cat('Showing df\n'); print(df); "
"sdf <- survdiff(Surv(t,d)~as.factor(g), data=df);"
"cat('Showing sdf\n'); print(sdf); "
"p.val <- 1 - pchisq(sdf$chisq, length(sdf$n) - 1);"
"trend <- (sdf$obs - sdf$exp)<0;"
"if (trend[2]==FALSE) {p.val <- 0.9999};"
"p.val"; //return the p.val of survdiff
p_val = R.parseEval(txt);
delete [] g;
return p_val;
}
int main(int argc, char* argv[]){
printf("get in\n");
RInside R(argc, argv);
double t[] = {1.0, 2.0, 3, 0.3, 4, 0.9, 5, 8.9, 10, 0.5};
int d[] = {1, 1, 0, 0, 0, 1, 0, 1, 0, 1};
int sample_size = 5;
double p_val = 0.0;
p_val = two_sample_logrank(R, t, d, sample_size);
printf("get out with %2.4f\n:", p_val);
}
On Sat, Feb 11, 2012 at 12:28 AM, Dirk Eddelbuettel <edd at debian.org> wrote:
On 10 February 2012 at 16:57, Haiying Pang wrote:
|
| I am calling a R function through Rcpp and RInside in my c++ program in
Linux.
| There are a lot of warning messages saying "no graphics system to
unregister"
| that were outputed to my log file, which leaded to a hug log file that I
can
| hardly open after letting the code run for a few hours. Is there anyone
who
| knows the reason and how to avoid the printing of such warning messages?
I
| appreciate for your help!
Without a minimal reproducible example, nobody is going to be able to help
you.
Dirk
--
"Outside of a dog, a book is a man's best friend. Inside of a dog, it is
too
dark to read." -- Groucho Marx
Thanks for sending an example. I am not so familiar with the survival
package. Does it create plots by default? If so, can you suppress them?
Can you reduce your program into smaller pieces not exhibiting the warning?
Dirk
On 13 February 2012 at 13:26, Haiying Pang wrote:
| Here is the test code I first used to call the R function from C++ program. At
| the end, the warning message came out.
|
| double two_sample_logrank(RInside R, double* t, int* d, int sample_size)
| {
| double p_val = 0;
| int n = 2*sample_size;
| std::string txt = ? ? ? ? ? ? ? ? ? // load library, run regression,
| create summary
| ? ? ? ? "suppressMessages(require(splines));"
| "suppressMessages(require(survival))";
| R.parseEvalQ(txt); ? ? ? ? ? ? ? ? ?// eval command, no return
|
| double* g = new double[n];
| int i = 0;
| for(i=0; i<sample_size; i++) g[i] = 1;
| for(i=sample_size; i<n; i++) g[i] = 2;
| /* construct vectors used in R from double* and int* */
| std::vector<double> std_t(t, &t[n]);
| R["t"] = std_t;
| std::vector<int> std_d(d, &d[n]);
| R["d"] = std_d;
| std::vector<int> std_g(g, &g[n]);
| R["g"] = std_g;
|
| txt = "df <- data.frame(t,d,g);"
| "cat('Showing df\n'); print(df); "
| "sdf <- survdiff(Surv(t,d)~as.factor(g), data=df);"
| "cat('Showing sdf\n'); print(sdf); "
| "p.val <- 1 - pchisq(sdf$chisq, length(sdf$n) - 1);"
| "trend <- (sdf$obs - sdf$exp)<0;"
| "if (trend[2]==FALSE) {p.val <- 0.9999};"
| "p.val"; //return the p.val of survdiff
| p_val = R.parseEval(txt);
|
| delete [] g;
| return p_val;
| }
|
| int main(int argc, char* argv[]){
| printf("get in\n");
|
| RInside R(argc, argv);
| double t[] = {1.0, 2.0, 3, 0.3, 4, 0.9, 5, 8.9, 10, 0.5};
| int d[] = {1, 1, 0, 0, 0, 1, 0, 1, 0, 1};
| int sample_size = 5;
| double p_val = 0.0;
| p_val = two_sample_logrank(R, t, d, sample_size);
| printf("get out with %2.4f\n:", p_val);
| }
|
|
|
|
| On Sat, Feb 11, 2012 at 12:28 AM, Dirk Eddelbuettel <edd at debian.org> wrote:
|
|
| On 10 February 2012 at 16:57, Haiying Pang wrote:
| | ?
| | I am calling a R function through Rcpp and RInside in my c++ program in
| Linux.
| | There are a lot of warning messages saying "no graphics system to
| unregister"
| | that were outputed to my log file, which leaded to a hug log file that I
| can
| | hardly open after letting the code run for a few hours. Is there anyone
| who
| | knows the reason and how to avoid the printing of such warning messages?
| I
| | appreciate for your help!
|
| Without a minimal reproducible example, nobody is going to be able to help
| you.
|
| Dirk
|
| --
| "Outside of a dog, a book is a man's best friend. Inside of a dog, it is
| too
| dark to read." -- Groucho Marx
|
|
|
|
| --
| Haiying Pang
"Outside of a dog, a book is a man's best friend. Inside of a dog, it is too
dark to read." -- Groucho Marx
Darren,
I did create the R instance in main(), and pass the reference to another
function. I do have 1000 CPUs calling that function, but as they don't
create new R reference, how come there are so many warning messages?
After reading your message in another thread of yours, I realize that the
troublesome part might be that the R reference is passed to a function that
many other CPUs call. what should I do to fix it? if I let each cpu creates
its own instance of R, will that end up with more warning messages?
On Sat, Feb 11, 2012 at 8:34 PM, Darren Cook <darren at dcook.org> wrote:
I am calling a R function through Rcpp and RInside in my c++ program
in Linux. There are a lot of warning messages saying "no graphics
system to unregister" ...Is there anyone who knows the reason and how
to avoid the printing of such warning messages?
Generally, once you track down the line causing the problem,
suppressWarnings() (an R function) might help. Or
suppressPackageStartupMessages() or suppressMessages() may help.
For the cause, are you running on a machine with no GUI or X server?
However, a google suggests this is a message related to shutting down R,
and implies your script has corrupted something. There appears to be no
fix as they, like Dirk, insisted on a reproducible example.
I'm wondering why you would be starting up and shutting down R so many
times in your script. Do you create one RInside instance, either as a
global, or in main() and then pass it around by reference? Or are you
create RInside instances inside other functions, or inside loop bodies?
If the latter, can you refactor to do the former so you only have one
instance?
HTH,
Darren
--
Darren Cook, Software Researcher/Developer
http://dcook.org/work/ (About me and my work)
http://dcook.org/blogs.html (My blogs and articles)
| Darren,
|
| I did create the R instance in main(), and pass the reference to another
| function. I do have 1000 CPUs calling that function, but as they don't create
| new R reference, how come there are so many warning messages? ??
|
| After reading your message in another thread of yours, I realize that the
| troublesome part might be that the R reference is passed to a function that
| many other CPUs call. what should I do to fix it? if I let each cpu creates its
| own instance of R, will that end up with more warning messages? ?
Now we're talking. Thanks for actually sharing your problem in proper terms.
In short, you can't do that.
R is single threaded, and you have to make sure that only thread calls back
to R. If you have a suitable problem, you can do what is shown in the mpi/
example directory: wrap RInside inside on an MPI aware program. That way MPI
takes care of getting your program to the nodes, and each node gets its own
copy. Naturally, this means that you cannot just work on one large chunk of
data. You need to think your problem through, and maybe RInside is simply
not part of the solution --- it does make any R restrictions (such as single
threadedness) go away.
Dirk
| On Sat, Feb 11, 2012 at 8:34 PM, Darren Cook <darren at dcook.org> wrote:
|
| > I am calling a R function through Rcpp and RInside in my c++ program
| > in Linux. There are a lot of warning messages saying "no graphics
| > system to unregister" ...Is there anyone who knows the reason and how
| > to avoid the printing of such warning messages?
|
| Generally, once you track down the line causing the problem,
| suppressWarnings() (an R function) might help. Or
| suppressPackageStartupMessages() or suppressMessages() may help.
|
| For the cause, are you running on a machine with no GUI or X server?
|
| However, a google suggests this is a message related to shutting down R,
| and implies your script has corrupted something. There appears to be no
| fix as they, like Dirk, insisted on a reproducible example.
|
| I'm wondering why you would be starting up and shutting down R so many
| times in your script. Do you create one RInside instance, either as a
| global, or in main() and then pass it around by reference? Or are you
| create RInside instances inside other functions, or inside loop bodies?
| If the latter, can you refactor to do the former so you only have one
| instance?
|
| HTH,
| Darren
|
|
| --
| Darren Cook, Software Researcher/Developer
|
| http://dcook.org/work/ (About me and my work)
| http://dcook.org/blogs.html (My blogs and articles)
| _______________________________________________
| Rcpp-devel mailing list
| Rcpp-devel at lists.r-forge.r-project.org
| https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
|
|
|
|
| --
| Haiying Pang
|
| ----------------------------------------------------------------------
| _______________________________________________
| Rcpp-devel mailing list
| Rcpp-devel at lists.r-forge.r-project.org
| https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
"Outside of a dog, a book is a man's best friend. Inside of a dog, it is too
dark to read." -- Groucho Marx
Thanks, Dirk, for the message. I did wrap the instance of RInside within an
MPI aware program to let MPI handle passing the copies to all the nodes.
The error I have found so far is that I didn't pass the R reference
correctly, and that causes the huge output of the warning messages. I have
corrected it in the test code and the warning message has gone. now I am
testing it in the MPI setting..
On Mon, Feb 13, 2012 at 2:13 PM, Dirk Eddelbuettel <edd at debian.org> wrote:
On 13 February 2012 at 13:38, Haiying Pang wrote:
| Darren,
|
| I did create the R instance in main(), and pass the reference to another
| function. I do have 1000 CPUs calling that function, but as they don't
create
| new R reference, how come there are so many warning messages?
|
| After reading your message in another thread of yours, I realize that the
| troublesome part might be that the R reference is passed to a function
that
| many other CPUs call. what should I do to fix it? if I let each cpu
creates its
| own instance of R, will that end up with more warning messages?
Now we're talking. Thanks for actually sharing your problem in proper
terms.
In short, you can't do that.
R is single threaded, and you have to make sure that only thread calls back
to R. If you have a suitable problem, you can do what is shown in the mpi/
example directory: wrap RInside inside on an MPI aware program. That way
MPI
takes care of getting your program to the nodes, and each node gets its own
copy. Naturally, this means that you cannot just work on one large chunk
of
data. You need to think your problem through, and maybe RInside is simply
not part of the solution --- it does make any R restrictions (such as
single
threadedness) go away.
Dirk
| On Sat, Feb 11, 2012 at 8:34 PM, Darren Cook <darren at dcook.org> wrote:
|
| > I am calling a R function through Rcpp and RInside in my c++
program
| > in Linux. There are a lot of warning messages saying "no graphics
| > system to unregister" ...Is there anyone who knows the reason and
how
| > to avoid the printing of such warning messages?
|
| Generally, once you track down the line causing the problem,
| suppressWarnings() (an R function) might help. Or
| suppressPackageStartupMessages() or suppressMessages() may help.
|
| For the cause, are you running on a machine with no GUI or X server?
|
| However, a google suggests this is a message related to shutting
down R,
| and implies your script has corrupted something. There appears to be
no
| fix as they, like Dirk, insisted on a reproducible example.
|
| I'm wondering why you would be starting up and shutting down R so
many
| times in your script. Do you create one RInside instance, either as a
| global, or in main() and then pass it around by reference? Or are you
| create RInside instances inside other functions, or inside loop
bodies?
| If the latter, can you refactor to do the former so you only have one
| instance?
|
| HTH,
| Darren
|
|
| --
| Darren Cook, Software Researcher/Developer
|
| http://dcook.org/work/ (About me and my work)
| http://dcook.org/blogs.html (My blogs and articles)
| _______________________________________________
| Rcpp-devel mailing list
| Rcpp-devel at lists.r-forge.r-project.org
|
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
|
|
|
|
| --
| Haiying Pang
|
| ----------------------------------------------------------------------
| _______________________________________________
| Rcpp-devel mailing list
| Rcpp-devel at lists.r-forge.r-project.org
| https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
--
"Outside of a dog, a book is a man's best friend. Inside of a dog, it is
too
dark to read." -- Groucho Marx
Here is the test code I first used to call the R function from C++
program. At the end, the warning message came out.
double two_sample_logrank(RInside R, double* t, int* d,
int sample_size){ ...
I think you've worked this out, but I thought this line should have been:
double two_sample_logrank(RInside &R, double* t, int* d,
int sample_size){ ...
Dirk/Romain: A quick look at the source [1] shows no copy constructor
has been defined, which means a default one will be created that will do
copy-by-value on all member variables... and that looks dangerous.
How about making copy private [2]? E.g. adding this section at the end
of the class definition in RInside.h:
private:
RInside(const RInside&){
throw std::logic_error("Copy not allowed");
}
RInside& operator= (const RInside&){
throw std::logic_error("Assignment not allowed");
}
(I had them throw in order to catch any copy attempt from inside the
RInside class itself.)
If copy-by-value is safe, and/or copy is needed in certain
circumstances, then ignore all that :-)
Darren
[1]:
https://r-forge.r-project.org/scm/viewvc.php/pkg/inst/include/RInside.h?view=markup&root=rinside
https://r-forge.r-project.org/scm/viewvc.php/pkg/src/RInside.cpp?view=markup&revision=227&root=rinside
[2]: http://www.devx.com/tips/Tip/12570
| > Here is the test code I first used to call the R function from C++
| > program. At the end, the warning message came out.
| >
| > double two_sample_logrank(RInside R, double* t, int* d,
| > int sample_size){ ...
|
| I think you've worked this out, but I thought this line should have been:
| double two_sample_logrank(RInside &R, double* t, int* d,
| int sample_size){ ...
|
| Dirk/Romain: A quick look at the source [1] shows no copy constructor
| has been defined, which means a default one will be created that will do
| copy-by-value on all member variables... and that looks dangerous.
|
| How about making copy private [2]? E.g. adding this section at the end
| of the class definition in RInside.h:
|
| private:
| RInside(const RInside&){
| throw std::logic_error("Copy not allowed");
| }
| RInside& operator= (const RInside&){
| throw std::logic_error("Assignment not allowed");
| }
|
| (I had them throw in order to catch any copy attempt from inside the
| RInside class itself.)
|
| If copy-by-value is safe, and/or copy is needed in certain
| circumstances, then ignore all that :-)
It's not a bad idea. I am trying to remember why I didn't do that when I
added the 'singleton-alike' hidden instance and initialize method...
Dirk
| [2]: http://www.devx.com/tips/Tip/12570
PS Don't you find devx a little icky?
"Outside of a dog, a book is a man's best friend. Inside of a dog, it is too
dark to read." -- Groucho Marx